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

📄 lcd1602.h

📁 485.rar
💻 H
字号:
//1602LCD驱动程序



sbit RS	= P3^2;		//
sbit RW = P3^3;
sbit E = P3^7;

/******************************************
*  nops: 短时间延时
*  入口参数: 无
*  出口参数: 无
******************************************/
void nops()
{
	_nop_();
	_nop_();
	_nop_();
	_nop_();
}

/******************************************
*  busy: 测试LCD忙碌状态
*  入口参数: 无
*  出口参数: 忙返回1,不忙返回0
******************************************/
bit busy()
{							

// 测试LCD忙碌状态
	bit result;
	RS = 0;
	RW = 1;
	E = 1;
	nops();
	P1 = 0xff;
	result = (bit)(P1 & 0x80);
	E = 0;
	return result;	
}

/******************************************
*  wcmd: 发送命令字程序模块
*  入口参数: unsigned char c
*  出口参数: 无
******************************************/
void wcmd(unsigned char c)
{
	while(busy());  //检测忙信号
	RS = 0;
	RW = 0;
	E = 0;
	_nop_();
	_nop_();	
	P1 = c;
	nops();
	E = 1;
	nops();
	E = 0;
}		

/******************************************
*  wdate: 发送数据程序模块
*  入口参数: unsigned char c
*  出口参数: 无
******************************************/
void wdate(unsigned char c)
{
	while(busy());  //检测忙信号
	RS = 1;
	RW = 0;
	E = 0;	
	P1 = c;
	nops();
	E = 1;
	nops();
	E = 0;	
}

/******************************************
*  wstr: 发送字符串程序模块
*  入口参数: unsigned char *s
*  出口参数: 无
******************************************/
void wstr(unsigned char *s)
{
	for(;*s != '\0';s++)
		{
			wdate(*s);
		}
}

/******************************************
*  wdec: 把32位字长的数以十进制数形式显示
*  入口参数: unsigned long x
*  出口参数: 无
******************************************/
void wdec(unsigned long x)   
{	 
	unsigned char k[11];
	int i = 10;
	while(x/10)
		{k[i]=x%10;x/=10;i--;}
	k[i]=x; //最高位
	for(i;i<11;i++)
		{
			wdate(0x30+k[i]);
		}
}

/******************************************
*  loc: 		改变光标定位
*  入口参数: 	x:行选(1或2),列选(1到16)
*  出口参数: 	无
******************************************/
void loc(unsigned char x,unsigned char y)
{
	if(x==1) y += 0x7f;
	 else if(x==2)y += 0xbf;
	 wcmd(y); 
}


/******************************************
*  wch: 	 	写汉字
*  入口参数: 	n:汉字的位置(0:7),*p:字模数组入

*  出口参数: 	无
******************************************/
void wch(unsigned char n,unsigned char *p)
{
	unsigned char i;
	for(i=0;i<8;i++,p++)
	{
		wcmd(0x40+n*8+i);
		wdate(*p);
	}	
}

⌨️ 快捷键说明

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