#include<STC12C5A60S2.h> #define LCD1602_DB P0 sbit LCD1602_RS = P2^0; sbit LCD1602_RW = P2^1; sbit LCD1602_E = P1^2; void InitLcd1602(); void LcdshowStr(unsigned char x , unsignedchar y , unsigned char *str); void LcdSetCursor(unsigned char x ,unsigned char y); void LcdWaitReady(); void LcdWritecmd(unsigned char cmd); void LcdSetCursor(unsigned char x ,unsigned char y); void delay(int ms); void main() { unsigned char str[] = "2022/10/25"; unsignedchar wy[] = "karyl-wy"; InitLcd1602(); LcdshowStr(0,1,str); LcdshowStr(0,0,wy); while(1); } void LcdWriteDat(unsigned char dat) { LcdWaitReady(); LCD1602_RS=1; LCD1602_RW=0; LCD1602_DB= dat; delay(1); LCD1602_E=1; delay(1); LCD1602_E=0; } void LcdWaitReady() { unsigned char sta; LCD1602_RS=0; LCD1602_RW = 1; LCD1602_DB= 0xFF; do{ LCD1602_E=1; sta=LCD1602_DB; LCD1602_E=0; }while(sta&0x80); } void LcdWritecmd(unsigned char cmd) { LcdWaitReady(); //??STA7=0 LCD1602_RS=0; LCD1602_RW=0; LCD1602_DB= cmd; delay(1); LCD1602_E=1; delay(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, unsignedchar y ,unsigned char*str) { LcdSetCursor(x,y); while(*str!='\0') { LcdWriteDat(*str++); } } void InitLcd1602() { LcdWritecmd(0x38); LcdWritecmd(0x0c); LcdWritecmd(0x06); LcdWritecmd(0x01); } void delay(int ms) { ms*=180; while(ms) { ms--; } }
|