资源描述:
《1602液晶显示电子钟时间C程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintsbitRS=P2^0;sbitRW=P2^1;sbitE=P2^2;sbitkey1=P2^3;sbitkey2=P2^4;sbitkey3=P2^5;voiddelay(void);voidinit(void);voidwc51r(uchari);voidwc51ddr(uchari);voidfbusy(void);voidLCD_xianshi(void);voiddelay_zs(ui
2、ntz);voidtiaoshi(void);ucharhour,hour1,min,min1,sec,sec1,aa,bb,num1,num2,num3,flag;ucharyear1,year2,year3,year4,month,month1,month2,day,day1,day2;unsignedintyear;uchartab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};voidmain(){init();while(1){LCD_xiansh
3、i();}}voidinit(){//key1=1;key2=1;key3=1;num1=12;year=2010;month=11;day=15;//wc51r(0x01);wc51r(0x38);wc51r(0x0c);wc51r(0x06);TMOD=0x01;//工作方式1TH0=(65536-5000)/256;//定时器高位装初值计数溢出一次为50msTL0=(65536-5000)%256;//定时器低位装初值EA=1;//CPU开中断ET0=1;//允许T0中断//ET1=1;TR0=1;//启动T0工
4、作//TR1=1;}voidfbusy(){RW=1;RS=0;E=1;while(!P1&0x80);E=0;delay();}voidwc51r(ucharj){fbusy();E=0;RS=0;RW=0;E=1;P1=j;E=0;delay();}voidwc51ddr(ucharj){fbusy();E=0;RS=1;RW=0;E=1;P1=j;E=0;delay();}voiddelay(){uchari,j;for(j=0;j<10;j++)for(i=0;i<10;i++);}/*voiddelay_zs
5、(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}*/voidLCD_xianshi(){year1=year/1000;year2=year/100%10;year3=year%100/10;year4=year%10;month1=month/10;month2=month%10;day1=day/10;day2=day%10;hour=num1/10;hour1=num1%10;min=num2/10;min1=num2%10;sec=num3/10;sec1
6、=num3%10;wc51r(0x84);//起始地址为第1行第1列,0x85为第1行第6列;0xc0为第2行第1列wc51ddr(tab[hour]);//显示1wc51ddr(tab[hour1]);//显示2wc51ddr(0x3a);//显示:wc51ddr(tab[min]);//显示0wc51ddr(tab[min1]);//显示0wc51ddr(0x3a);//显示:wc51ddr(tab[sec]);wc51ddr(tab[sec1]);wc51r(0xc3);wc51ddr(tab[year1]);w
7、c51ddr(tab[year2]);wc51ddr(tab[year3]);wc51ddr(tab[year4]);wc51ddr('-');wc51ddr(tab[month1]);wc51ddr(tab[month2]);wc51ddr('-');wc51ddr(tab[day1]);wc51ddr(tab[day2]);}/*voidtiaoshi(void){while(key1){TR0=0;if(key2==0){LCD_xianshi;num3++;if(num3==60){num3=0;num2++;
8、}}elseif(key3==0)num2++;}//while(key1);//if(key1==0){ET0=1;TR0=1;flag=0;}}*///************************定时器中断程序**************************//voidtimer0()interrupt1{TH0=(6