51单片机 1602液晶显示静态字符
扫描二维码
随时随地手机看文章
#include
#defineLCD1602_DBP0
typedefunsignedcharuchar;
typedefunsignedintuint;
typedefunsignedlongulong;
sbitLCD1602_RS=P1^0;
sbitLCD1602_RW=P1^1;
sbitLCD1602_E=P1^5;
voidinitLCD1602();
voidLCDShowStr(uchari,ucharj,uchar*pCh);
voidLCDWaitRdy();
voidLCDWrCmd(ucharcmd);
voidLCDWrData(uchardat);
voidLCDSetCursor(uchari,ucharj);
voidmain(){
initLCD1602();
LCDShowStr(0,1,"Helloworld!");
LCDShowStr(1,1,"ChasingWaves");
while(1);
}
voidLCDWaitRdy(){
ucharstate;
LCD1602_DB=0xFF;//使数据总线处于高电平
LCD1602_RS=0;//选择命令模式
LCD1602_RW=1;//选择读
do{
LCD1602_E=1;//开启液晶读写使能
state=LCD1602_DB;//从数据总线上读取状态字
LCD1602_E=0;//关闭液晶读写使能
}while(state&0x80);//重复直到bit7==0为止(不忙了)
}
voidLCDWrCmd(ucharcmd){
LCDWaitRdy();
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_DB=cmd;
LCD1602_E=1;
LCD1602_E=0;
}
voidLCDWrData(uchardat){
LCDWaitRdy();
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_DB=dat;
LCD1602_E=1;
LCD1602_E=0;
}
voidLCDSetCursor(uchari,ucharj){
ucharaddr=(i==0?j:0x40+j);
LCDWrCmd(addr|0x80);
}
voidLCDShowStr(uchari,ucharj,uchar*pch){
LCDSetCursor(i,j);
while(*pch!='