资源描述:
《1602程序源码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include"reg52.h"#defineucharunsignedcharsbitRW=P2^1;sbitRS=P2^0;sbitE=P2^2;bitat=0;ucharcodeshen[]={"CLOCKH"};ucharcodeword[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x20};uchardispbuf[8],h,m,s,counter;voiddelay(){uchari;for(i=0;i<255;i++);}/*******写命令**********/v
2、oidlcd_wmc(uchari){P0=i;RS=0;RW=0;E=0;delay();E=1;}/*******写数据***********/voidlcd_wmd(uchari){P0=i;RS=1;RW=0;E=0;delay();E=1;}/*******初始化液晶*******/voidlcd_init(){uchari;lcd_wmc(0x01);lcd_wmc(0x38);lcd_wmc(0x0c);lcd_wmc(0x06);lcd_wmc(0xc9);for(i=0;i<6;i++)lcd_wmd(shen[i]);lcd_wmc(0
3、xc0);}/*******更新缓冲区子程序*******/voidnewbuf(){dispbuf[0]=s%10;dispbuf[1]=s/10;dispbuf[3]=m%10;dispbuf[4]=m/10;dispbuf[6]=h%10;dispbuf[7]=h/10;}/*******显示子程序**********/voiddisp(uchardispadd){uchartmp;lcd_wmc(dispadd);tmp=dispbuf[7];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[6];tmp=word[tm
4、p];lcd_wmd(tmp);tmp=dispbuf[5];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[4];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[3];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[2];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[1];tmp=word[tmp];lcd_wmd(tmp);tmp=dispbuf[0];tmp=word[tmp];lcd_wmd(tmp);}/***********
5、**********键盘子程序***********************/ucharkeypro(void){ucharscanl,scanh;P1=0x0f;//先将所有行线拉低if((P1&0x0f)!=0x0f)//如果列线有变化{delay();//延迟一段时间。if((P1&0x0f)!=0x0f)//如果此时此刻列线还有变化,说明确实有按键按下{scanl=0xfe;while((scanl&0x10)!=0){P1=scanl;//给P1口赋扫描码,每次只拉低一行if((P1&0xf0)!=0xf0)//如果判断为真,则说明找到了按键按下
6、的行{scanh=(P1&0xf0)
7、0x0f;//计算识别码return(~scanh)+(~scanl);}elsescanl=(scanl<<1)
8、0x01;//否则依次将第二,第三,第四行拉低}}}return0;//没有按键按下返回0}/********************时间调整子程序********************/voidadjustime(){uchark;staticucharadd;k=keypro();switch(k){case0x88:if(!at){add=0xc1;EA=0;lcd_wmc(0xc1);lcd_w
9、mc(0x0f);at=1;}else{lcd_wmc(0xc0);lcd_wmc(0x0c);at=0;EA=1;}break;case0x48:if(at){if(add==0xc1){add=0xc7;lcd_wmc(add);}else{add=add-3;lcd_wmc(add);}}break;case0x28:if(at){if(add==0xc7){add=0xc1;lcd_wmc(add);}else{add=add+3;lcd_wmc(add);}}break;case0x18:if(at){if(add==0xc1)h++;if(h=
10、=24)h=0;if(add==0xc4)m++;if(m==60