⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd12232._c

📁 用ICC-AVR编译器编译M16单片机适用的LCD12232液晶屏驱动程序.
💻 _C
字号:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//					    LCD12232 Library for AVR 
//								  V0.1c
// 	  							 zhongwh
//							Copyright 2003-2005 
//   					   Email: hfkj01@163.com
//						    2005-6-19 15:38:52
//			    Compiled with Imagecraft C Compiler for the AVR series
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#include <iom16v.h>
#define prepage 0xB8
#define precol 0X00
#define	E1_H  PORTD|=BIT(PD4);
#define	E1_L  PORTD&=~BIT(PD4);
#define	A0_H  PORTD|=BIT(PD7);
#define	A0_L  PORTD&=~BIT(PD7);
#define	LCD_READ  PORTD|=BIT(PD6);
#define	LCD_WRITE PORTD&=~BIT(PD6);
#define	E2_H  PORTD|=BIT(PD5);
#define	E2_L  PORTD&=~BIT(PD5);
#define	LCD_PCT		DDRC		   
#define	LCD_IN		PINC
#define	LCD_DATA	PORTC
#define uchar unsigned char
uchar	b1=0,pianyi=0x41,sz0=0x41,sz1=0x41,sz2=0x41,sz3=0x41,sz4=0x41,sz5=0x41;
const char chartable[35][32];
void wcodel (uchar c)
{	 uchar status;
 	 
	 while(1){
	          LCD_PCT=0X00;
			  E1_H 
			  A0_L
			  LCD_READ
			  E1_L
			  status=LCD_IN;
			  status=status&0x80;
			if (status==0) break;
			}
	LCD_PCT=0XFF;
	E1_H 
	LCD_WRITE
	LCD_DATA=c;
    E1_L
	
}
void wdatal (uchar d)
{	 uchar status;
 	 
	  while(1){   
	 		  LCD_PCT=0X00;
			  E1_H
			  A0_L
			  LCD_READ
			  E1_L
			  status=LCD_IN;
			  status=status&0x80;
			if (status==0) break;
			} 
	LCD_PCT=0XFF;	
	E1_H		
	A0_H
	LCD_WRITE
	LCD_DATA=d;
    E1_L
	
}		
void wcoder (uchar c)
{	 uchar status;
 	 
	 while(1){
	 		  LCD_PCT=0X00;
	   		  E2_H
	 		  A0_L
			  LCD_READ
		      E2_L
			  status=LCD_IN;
			  status=status&0x80;
			  if (status==0) 
			   	{ break;}
			}
	LCD_PCT=0XFF;
	E2_H
	LCD_WRITE		
	LCD_DATA=c;
	E2_L
	
}			
void wdatar (uchar d)
{	 uchar status;
 	 
	 while(1){ LCD_PCT=0X00;
	 		  E2_H
	 		  A0_L
			  LCD_READ
		      E2_L
			  status=LCD_IN;
			  status=status&0x80;
			if (status==0) break;
			}	
	LCD_PCT=0XFF;
	E2_H
	A0_H
	LCD_WRITE
	LCD_DATA=d;
    E2_L
	
}		


void clear(uchar symbol)
{
uchar page=0x00;
uchar col=0x00;
	 for (page=0x00;page<0x04;page++)
	 {
	 
	  	 wcodel(prepage+page);
		 
		 for (col=0x00;col<0x61;col++)
		 	 {
			 wcodel(precol+col);
			 wdatal(symbol);
			 }
	}
	for (page=0x00;page<0x04;page++)
	{
	 	wcoder(prepage+page);
		
		for (col=0x00;col<0x61;col++)
		{
		 	wcoder(precol+col);
			wdatar(symbol);
		}
	}
}
//
void addressl(uchar page,uchar col)
{
 	 wcodel(prepage+page);
	 wcodel(precol+col);
}
//
void addressr(uchar page,uchar col)
{	 
 	 wcoder(prepage+page);
	 wcoder(precol+col+3);
}	
// 	 
void lcdinit(void)
{	 PORTC=0XFF;
	 DDRC=0X00;
	 DDRD=0XFF;
	 DDRA|=BIT(PA7);
	 PORTA|=BIT(PA7);
	 wcodel(0xe2);wcoder(0xe2);//reset
	 wcodel(0xae);wcoder(0xae);//display off	
	 wcodel(0xA4);wcoder(0xA4);//display off 
	 wcodel(0xa9);wcoder(0xa9);//duty select :1/32
	 wcodel(0xa0);wcoder(0xa0);//clock
	 wcodel(0xEE);wcoder(0xEE);//display off
	 wcodel(0xc0);wcoder(0xc0);//start line: 1
	 wcodel(0x00);wcoder(0x00); //column address set:0
	 clear(0X00);
	 wcodel(0xAF);wcoder(0xAF);//page address set:1

} 
void displaystring(uchar x,uchar y,uchar *onechar)
{
 	 uchar i=0,z=0,j=0,w;
	 w=y;
	 if (y>60)
	 {
	  	y=y-61;
	 	addressr(x,y);
		while((*onechar)!='\n')
	 	 {
	 	  	for (i=0;i<16;i++)
			{if(b1==0){pianyi=0x41;}else{switch(z){case 3:pianyi=sz3;break;case 4:pianyi=sz4;break;case 5:pianyi=sz5;break;}}
			 wdatar(chartable[*onechar-pianyi][i]);}
			 onechar++;
			 z++;
		 }
	  }
	 else
	 {
	  addressl(x,y);
	  addressr(x,-3);
	 
	  while((*onechar)!='\n')
	  {
	  	for (i=0;i<16;i++)
		{if(b1==0){pianyi=0x41;}else{switch(z){case 0:pianyi=sz0;break;case 1:pianyi=sz1;break;case 2:pianyi=sz2;break;}}
		 wdatal(chartable[*onechar-pianyi][i]);}
		onechar++;
		z++;
	 	j++;
		if (j>2) break;
 	  }
	 
	    while((*onechar)!='\n')
	 	   {
	 	   		for (i=0;i<16;i++)
				{if(b1==0){pianyi=0x41;}else{switch(z){case 3:pianyi=sz3;break;case 4:pianyi=sz4;break;case 5:pianyi=sz5;break;}}
	 			wdatar(chartable[*onechar-pianyi][i]);}
				onechar++;
				z++;
	       }
	    }
	//
	onechar=onechar-z;
	z=0;
	j=0;
		 if (w>60)
	 {
	  	w=w-61;
	 	addressr(x+1,w);
		while((*onechar)!='\n')
	 	 {
	 	  	for (i=16;i<32;i++)
			{if(b1==0){pianyi=0x41;}else{switch(z){case 3:pianyi=sz3;break;case 4:pianyi=sz4;break;case 5:pianyi=sz5;break;}}
	 		wdatar(chartable[*onechar-pianyi][i]);}
			 onechar++;
			 z++;
		 }
	  }
	 else
	 {
	  addressl(x+1,w);
	  addressr(x+1,-3);
	 
	  while((*onechar)!='\n')
	  {
	  	for (i=16;i<32;i++)
		{if(b1==0){pianyi=0x41;}else{switch(z){case 0:pianyi=sz0;break;case 1:pianyi=sz1;break;case 2:pianyi=sz2;break;}}
		wdatal(chartable[*onechar-pianyi][i]);}
		onechar++;
		z++;
	 	j++;
		if (j>2) break;
 	  }
	 
	    while((*onechar)!='\n')
	 	   {
	 	   		for (i=16;i<32;i++)
				{if(b1==0){pianyi=0x41;}else{switch(z){case 3:pianyi=sz3;break;case 4:pianyi=sz4;break;case 5:pianyi=sz5;break;}}
	 			wdatar(chartable[*onechar-pianyi][i]);}
				onechar++;
				z++;
	       }
	    }
	//
	 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -