/*本程序实现独立键盘控制LCD显示字符串*/#includereg52.h#defineucharunsignedchar#defineuintunsignedintucharcodetable1[]=HELL0;ucharcodetable2[]=YOUAREWELCOME;sbitlcdrs=P1^0;sbitlcdrw=P1^1;sbitlcden=P2^5;sbitdula=P2^6;sbitwela=P2^7;sbitkey1=P3^4;sbitkey2=P3^5;uinti;/*延时函数*/voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}/*写命令函数*/voidwrite_com(ucharcom){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}/*写数据函数*/voidwrite_data(uchardate){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidinit(){dula=0;//关段码wela=0;//关位码lcden=0;lcdrw=0;write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口write_com(0x0e);//设置开显示,显示光标write_com(0x06);//写一个字符后地址指针加1write_com(0x01);//显示清零,数据指针清零}voidmain(){init();while(1){if(key1==0){write_com(0x80);delay(5);if(key1==0){for(i=0;i5;i++){write_data(table1[i]);delay(100);}}while(!key1);delay(5);}write_com(0x01);//显示清零,数据指针清零if(key2==0){delay(5);write_com(0x80+0x40);if(key2==0){for(i=0;i15;i++){write_data(table2[i]);delay(100);}}while(!key2);delay(5);write_com(0x01);//显示清零,数据指针清零}}}