第一行顯示"Welcome";第二行顯示="Happy day";若要顯示其他字符,請直接往數(shù)組 LCMLineOne[16]和LCMLineTwo[16]填充相應(yīng)的代碼。直接上圖,仿真圖如下:
源程序如下,可以對比時序方式,理解總線的操作方法。#includereg51.h>//#includeabsacc.h>#define uchar unsigned char#define uint unsigned int #define busy 0x80uchar xdata LCMWriteCOM _at_ 0x80ff; //寫指令寄存器uchar xdata LCMReadCOM _at_ 0xa0ff ; //讀指令寄存器uchar xdata LCMWriteData _at_ 0xc0ff ; //寫數(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++);}//寫指令寄存器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);}//寫數(shù)據(jù)寄存器帶地址void LCMWriteDAdd(uchar addr,uchar LCMData){uchar LCMStatus;do{LCMStatus=(LCMReadCOMbusy); }while(LCMStatus!=0);LCMWriteC(0x80+addr);LCMWriteData=LCMData;}//寫數(shù)據(jù)寄存器無地址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); //第一行開始地址for(i=0;i16;i++)LCMWriteD(LCMLineOne[i]);LCMWriteC(0x80+0x40); //第二行開始地址for(i=0;i16;i++)LCMWriteD(LCMLineTwo[i]);}}
評論