/////LCM_start/////
/*============================================================
1602LCD四位数据接口驱动程序 马文垒 2004/12/13
==============================================================
感谢:本程序参考 明皓的1602LCM液晶显示屏的驱动函数和实例
连接线图:
----------------------------------
| LCM-----51 | LCM-----51 |
----------------------------------
|RS-----P2.1 | DB4-----P1.4 |
|RW-----P2.0 | DB5-----P1.5 |
|E -----P2.2 | DB6-----P1.6 |
|VLCD接1K电阻到GND| DB7-----P1.7 |
---------------------------------------------------
[注:AT89S51使用12M晶振]
=============================================================*/
void writelcd(bit command,unsigned char ddata)
{
ReadStatusLCM(); //检测忙
LCM_Data = (ddata&0xf0)|(P1&0x0f);
LCM_RW = 0;
if(command==0) LCM_RS = 0; else LCM_RS=1;
LCM_E = 1;
LCM_E = 0;
LCM_E = 0;
LCM_Data = ((ddata<<4)&0xf0)|(P1&0x0f);
if(command==0) LCM_RS = 0; else LCM_RS=1;
LCM_E = 1;
LCM_E = 0;
LCM_E = 0;
}
//读状态
unsigned char ReadStatusLCM(void)
{
P1_7=1;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
while(P1_7&0x01);//检测忙信号
return(P1_7);
}
void LCMInit(void) //LCM初始化
{
LCM_Data=0xff;
writelcd(0,0x28); //三次显示模式设置,不检测忙信号
Delay5Ms();
writelcd(0,0x28);
Delay5Ms();
writelcd(0,0x28);
Delay5Ms();
writelcd(0,0x28); //显示模式设置,开始要求每次检测忙信号
writelcd(0,0x0c); // 显示开及光标设置
writelcd(0,0x01); //显示清屏
writelcd(0,0x06); // 显示光标移动设置
}
//按指定位置显示一个字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1; X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; //算出指令码
writelcd(0,X);
writelcd(1,DData);
}
//按指定位置显示一串字符 ***原来的遇到空格0x20就不显示***
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength,j;
ListLength = strlen(DData);
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (X <= 0xF) //X坐标应小于0xF
{
for(j=0;j<ListLength;j++)
{
DisplayOneChar(X, Y, DData[j]); //显示单个字符
X++;
}
}
}
//5ms延时
void Delay5Ms(void)
{
unsigned int TempCyc = 5552;
while(TempCyc--);
}
//400ms延时
void Delay400Ms(void)
{
unsigned char TempCycA = 5;
unsigned int TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
};
}
/////LCM_end///////
1602LCD四位数据接口驱动1602LCD四位数据接口驱动程序
更新时间: 2006-03-23 16:18:39来源: 粤嵌教育浏览量:4115