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

📄 lcd1602forlpc2144.c

📁 基于LPC2144的 LCD1602驱动
💻 C
字号:
/*===========================================================================

			KS0070(44780) 16x2 字符液晶屏驱动演示程序总线方式         
=============================================================================

*/
#define PIN_OE             1 << 14
#define PIN_RS             1 << 24  
#define PIN_RW             1 << 25

#define OE(x)              ((x) ? (IO0SET = PIN_OE)  : (IO0CLR = PIN_OE) );
#define RS(x)              ((x) ? (IO1SET = PIN_RS)  : (IO1CLR = PIN_RS) );
#define RW(x)              ((x) ? (IO1SET = PIN_RW)  : (IO1CLR = PIN_RW) );




#define Busy	0x00800000 						// 忙判别位


void Delay(uint32 d)
{
	while(--d);
}
/*=======================================================
正常读写操作之前必须检测LCD控制器状态:    CS=1 RS=0 RW=1
DB7:    0  LCD控制器空闲; 1  LCD控制器忙
========================================================*/
void WaitForEnable(void) {	
	IO0DIR = PIN_OE;
	IO1DIR = 0x03000000;					   	  				   
    RS(0); 
    RW(1); 
    OE(1);         
    Delay(400);
    while(IO1PIN & Busy);    
    OE(0);    
    IO1DIR = 0x03ff0000;
}
/*=======================================================
 写控制字符子程序: E=1 RS=0 RW=0
=======================================================*/
void LcdWriteCommand( Uchar CMD,Uchar AttribC ) 
{
	IO0DIR = PIN_OE;
	IO1DIR = 0x03ff0000;
	if(AttribC)WaitForEnable();    // 检测忙信号?		
	RS(0);
	RW(0);
	Delay(400);			
//	IO1CLR = 0x00ff0000;	
//	IO1SET = CMD << 16;		
    IO1PIN = (IO1PIN & 0xFF00FFFF) | CMD <<16;
	Delay(400);
	OE(1);	
	Delay(400);
	OE(0);	
}
/*=======================================================
 当前位置写字符子程序: E =1 RS=1 RW=0
=======================================================*/
void LcdWriteData( char dataW ) {
	IO0DIR = PIN_OE;
    WaitForEnable();			
	RS(1);
	RW(0);		
	Delay(400);			
//	IO1CLR = 0x00ff0000;
//	IO1SET = dataW << 16;		
	IO1PIN = (IO1PIN & 0xFF00FFFF) | dataW << 16;
	Delay(400);
	OE(1);	
	Delay(400);
	OE(0);	
	Delay(400);	
}
/*=======================================================
 显示光标定位
=======================================================*/
void LocateXY( char posx,char posy) {

Uchar temp;
    
	temp = posx & 0xf;
	posy &= 0x1;
	if ( posy )temp |= 0x40;
	temp |= 0x80;
	LcdWriteCommand(temp,0);
}
/*=======================================================
 按指定位置显示数出一个字符
=======================================================*/
void DispOneChar(Uchar x,Uchar y,Uchar Wdata) {

	LocateXY( x, y );				// 定位显示地址
    Delay(400);
	LcdWriteData( Wdata );			// 写字符
    Delay(400);
}

/*=======================================================
 显示字符串
=======================================================*/
void ePutstr(Uchar x,Uchar y, Uchar *ptr) {
Uchar i,l=0;
	while (ptr[l] > '\0'){l++;};
	for (i=0;i<l;i++) {
		DispOneChar(x++,y,ptr[i]);
		if ( x == 16 ){
			x = 0; y ^= 1;
		} 	  
	}
}

/*=======================================================
 显示光标定位闪烁

void Coruscant (Uchar x ,y) {
	LocateXY( x, y );
	LcdWriteCommand( 0x0f, 1);
}
=======================================================*/



/*=======================================================
 初始化程序, 必须按照产品资料介绍的初始化过程进行
=======================================================*/
// 短延时


void LcdReset( void ) {
	
	IO1DIR = 0x03FF0000;
	IO0DIR = PIN_OE;
    Delay(40000);
   	LcdWriteCommand( 0x30, 0);			// 显示模式设置(不检测忙信号)
		Delay(40000);
	LcdWriteCommand( 0x30, 0);			// 共三次
		Delay(40000);
	LcdWriteCommand( 0x30, 0);
		Delay(40000);
	LcdWriteCommand( 0x38, 1);			// 显示模式设置(以后均检测忙信号)
		Delay(40000);
    LcdWriteCommand( 0x08, 1);			// 显示关闭
		Delay(40000);
   	LcdWriteCommand( 0x01, 1);			// 显示清屏
		Delay(40000);
	LcdWriteCommand( 0x06, 1);			// 显示光标移动设置
		Delay(40000);
	LcdWriteCommand( 0x0c, 1);
		Delay(40000);    
}






 

⌨️ 快捷键说明

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