基于單片機(jī)的LCD1602控制總線模式
第一行顯示W(wǎng)elcome;第二行顯示=Happy day;若要顯示其他字符,請(qǐng)直接往數(shù)組 LCMLineOne[16]和LCMLineTwo[16]填充相應(yīng)的代碼。直接上圖,仿真圖如下:
本文引用地址:http://m.butianyuan.cn/article/170902.htm源程序如下,可以對(duì)比時(shí)序方式,理解總線的操作方法。
#includereg51.h>
//#includeabsacc.h>
#define uchar unsigned char
#define uint unsigned int
#define busy 0x80
uchar xdata LCMWriteCOM _at_ 0x80ff; //寫(xiě)指令寄存器
uchar xdata LCMReadCOM _at_ 0xa0ff ; //讀指令寄存器
uchar xdata LCMWriteData _at_ 0xc0ff ; //寫(xiě)數(shù)據(jù)寄存器
uchar xdata LCMReadData _at_ 0xe0ff ; //讀數(shù)據(jù)寄存器
uchar data LCMLineOne[16]=Welcome; //第一行顯示的數(shù)據(jù)
uchar data LCMLineTwo[16]=Happy day; //第二行顯示的數(shù)據(jù)
void Delayms(uchar ms)
{
uchar i,j;
for(i=0;ims;i++)
for(j=0;j57;j++)
;
}
//寫(xiě)指令寄存器
void LCMWriteC(uchar COMData)
{ uchar LCMStatus;
do
{
LCMStatus=(LCMReadCOMbusy);
}
while(LCMStatus!=0);
LCMWriteCOM=COMData;
}
//讀指令寄存器
uchar LCMReadC()
{uchar LCMStatus;
do
{
LCMStatus=(LCMReadCOMbusy);
}
while(LCMStatus!=0);
LCMStatus=LCMReadCOM;
return(LCMStatus);
}
//讀數(shù)據(jù)寄存器
uchar LCMReadD(uchar addr)
{uchar LCMStatus;
do
{
LCMStatus=(LCMReadCOMbusy);
}
while(LCMStatus!=0);
LCMWriteC(0x80+addr);
LCMStatus=LCMReadData;
return(LCMStatus);
}
//寫(xiě)數(shù)據(jù)寄存器帶地址
void LCMWriteDAdd(uchar addr,uchar LCMData)
{uchar LCMStatus;
do
{
LCMStatus=(LCMReadCOMbusy);
}
while(LCMStatus!=0);
LCMWriteC(0x80+addr);
LCMWriteData=LCMData;
}
//寫(xiě)數(shù)據(jù)寄存器無(wú)地址
void LCMWriteD(uchar LCMData)
{uchar LCMStatus;
do
{
LCMStatus=(LCMReadCOMbusy);
}
while(LCMStatus!=0);
LCMWriteData=LCMData;
}
//初始化
void LCMInit(void)
{ Delayms(15);
LCMWriteCOM=0x38;
Delayms(5);
LCMWriteCOM=0x38;
Delayms(5);
LCMWriteCOM=0x38;
Delayms(5);
LCMWriteC(0x38);
LCMWriteC(0x08);
LCMWriteC(0x01);
LCMWriteC(0x06);
LCMWriteC(0x0c);
}
main()
{ uchar i;
LCMInit();
while(1)
{ LCMWriteC(0x80); //第一行開(kāi)始地址
for(i=0;i16;i++)
LCMWriteD(LCMLineOne[i]);
LCMWriteC(0x80+0x40); //第二行開(kāi)始地址
for(i=0;i16;i++)
LCMWriteD(LCMLineTwo[i]);
}
}
評(píng)論