資源描述:
《hd44780 lcd源程序》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、HD44780LCD源程序/*LCD型號:HD44780*//*打印機型號:EPSONM311*/#include#include#include#defineucharunsignedchar#defineuintunsignedint//定義8255I/O端口地址#definePCC8255XBYTE[0x007f]//8255命令口地址#definePC8255XBYTE[0x007e]//8255的PC口地址#definePB8255XBYTE[0x007d]//8255的PC口地址#definePA82
2、55XBYTE[0x007c]//8255的PC口地址sfrRPCTL=0xD8;sbitRPCTL_5=RPCTL^5;sbitLS164A=P2^5;sbitLS164cp=P2^6;sbitPrint_busy=P3^3;sbitIC_RST=P1^1;sbitIC_CLK=P1^0;sbitIC_IO=P1^2;sbitIC_PGM=P3^2;ucharcodetable1[16]="FEDCBA9870123456";ucharcodetable2[16]="0000123456789ABC";voidINIT_8255(void);/*初始化8255*/voi
3、dLcdInit(void);/*LCD初始化函數(shù)*/voidLcdCmd(uchar);/*LCD控制命令函數(shù)*/voidLcdData(uchar);/*LCD數(shù)據(jù)輸入函數(shù)*/voidLcdClr(void);/*LCD清屏函數(shù)*/voidLcdStr(uchar*);/*顯示字符串函數(shù)*/voidLcdDisp(ucharx,uchard);voidDelay_msec(uintx);/*延時函數(shù)*/ucharGetkey(void);/*鍵盤函數(shù)*/voidPrintInit(void);/*打印初始化函數(shù)*/voidPrintData(uchard);/*打印函
4、數(shù)*/voidPrintString(uchar*p);//打印字符串voidLcdDisp(ucharx,uchard)//指定位置顯示字符x:LCD位置d:字符{if(x<9){LcdCmd(0x80+x);LcdData(d);}else{LcdCmd(0xc0+x);LcdData(d);}}voidLcdStr(uchar*p)/*顯示字符串函數(shù)*/{datauchari;LcdCmd(0x80);//設(shè)置顯示數(shù)據(jù)RAMfor(i=0;i<=7;i++){LcdData(*p);/*charofLCM*/p++;}LcdCmd(0xc0);//設(shè)置顯示數(shù)據(jù)RAM
5、for(i=0;i<=7;i++){LcdData(*p);/*charofLCM*/p++;}}voidLcdClr()/*LCD清屏函數(shù)?-----通過送0x20清屏*/{datauchari;LcdCmd(0x80);//設(shè)置顯示數(shù)據(jù)RAMfor(i=0;i<=7;i++)LcdData(0x20);/*charofLCM*/LcdCmd(0xc0);//設(shè)置顯示數(shù)據(jù)RAMfor(i=0;i<=7;i++)LcdData(0x20);/*charofLCM*/}voidLcdClr1(void)/*LCD清屏函數(shù)?-----通過控制命令清屏*/{LcdCmd(0x0
6、1);}voidLcdCmd(ucharc)/*LCD控制命令函數(shù)*/{RPCTL_5=1;Delay_msec(1);//延時1ms(1000us)PCC8255=0x00;PCC8255=0x02;PB8255=c;PCC8255=0x05;PCC8255=0x04;Delay_msec(1);//延時1ms(1000us)RPCTL_5=0;}voidLcdData(ucharc)/*LCD數(shù)據(jù)輸入函數(shù)*/{RPCTL_5=1;Delay_msec(1);//延時1ms(1000us)PCC8255=0x01;PCC8255=0x02;PB8255=c;PCC825
7、5=0x05;PCC8255=0x04;Delay_msec(1);//延時1ms(1000us)RPCTL_5=0;}voidLcdInit()/*LCD初始化函數(shù)*/{Delay_msec(41);//延時41msLcdCmd(0x3c);//設(shè)置字符參數(shù)LcdCmd(0x08);//設(shè)置顯示開/關(guān)LcdCmd(0x01);//清除顯示Delay_msec(41);//延時41msLcdCmd(0x06);//設(shè)置輸入方式LcdCmd(0x10);//設(shè)置顯示光標(biāo)移位LcdCmd(0x0c);//設(shè)置顯示開/關(guān)}voidD