完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include #define LCD1602_DB P0 ***it LCD1602_RS=P1^0; ***it LCD1602_RW=P1^1; ***it LCD1602_E=P1^5; void InitLcd1602(); void LcdShowStr(unsigned char x,unsigned char y,unsigned char*str); void main() { unsigned char str[]={ 0x03,0x07,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F, //左上 0x18,0x1E,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, //左中上 0x03,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, //右中上 0x18,0x1C,0x1E,0x1F,0x1F,0x1F,0x1F,0x1F}; //右上 unsigned char stb[]={ 0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00, //左下 0xFF,0xFF,0xFF,0xFF,0x0F,0x03,0x01,0x00, //左中下 0x1F,0x1F,0x1F,0x1F,0x1E,0x18,0x10,0x00, //右中下 0x1E,0x1C,0x18,0x10,0x00,0x00,0x00,0x00}; //右下 InitLcd1602(); LcdShowStr(str); LcdShowStr(stb); while(1); } void LcdWaitReady() { unsigned char sta; LCD1602_DB=0xFF; LCD1602_RS=0; LCD1602_RW=1; do{ LCD1602_E=1; sta=LCD1602_DB; LCD1602_E=0; } while(sta&0x80); } void LcdWriteCmd(unsigned char cmd) { LcdWaitReady(); LCD1602_RS=0; LCD1602_RW=0; LCD1602_DB=cmd; LCD1602_E=1; LCD1602_E=0; } void LcdWriteDat(unsigned char dat) { LcdWaitReady(); LCD1602_RS=1; LCD1602_RW=0; LCD1602_DB=dat; LCD1602_E=1; LCD1602_E=0; } void LcdSetCursor(unsigned char x,unsigned char y) { unsigned char addr; if(y==0) addr=0x00+x; else addr=0x40+x; LcdWriteCmd(addr|0x80); } void LcdShowStr(unsigned char x,unsigned char y,unsigned char*str) { LcdSetCursor(x,y); while(*str!=' |