1602显示时钟Word下载.docx
《1602显示时钟Word下载.docx》由会员分享,可在线阅读,更多相关《1602显示时钟Word下载.docx(16页珍藏版)》请在冰豆网上搜索。
voiddelay()
{
uchari;
for(i=0;
i<
5;
i++);
}
voiddelay5ms(uintj)
uinta,b;
for(a=j;
a>
0;
a--)
for(b=100;
b>
b--);
voidinit_time0()
EA=1;
ET0=1;
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
TR0=1;
voidwrite_com(ucharcom)
rs=0;
e=0;
_nop_();
P0=com;
e=1;
voidwrite_date(uchardate)
rs=1;
P0=date;
voidlcd_init()
write_com(0x01);
delay();
write_com(0x3c);
write_com(0x0c);
write_com(0x06);
//delay();
voidsec_init()
write_com(0x0f);
voidtime0()interrupt1
count++;
voiddisplay()
if(count==17)
{
count=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
day++;
if((mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)&
&
day==32)
{
day=1;
mon++;
}
elseif((mon==4||mon==6||mon==9||mon==11)&
day==31)
elseif(mon==2)
if((year/4==0&
year/100!
=0)||(year/4==0&
year/400==0))
{
if(day==30)
day=1;
mon++;
}
elseif(!
((year/4==0&
=0)&
(year/100==0&
year/400==0)))
if(day>
28)
{
day=1;
}
}
if(mon==13)
mon=1;
year++;
}
}
}
}
voidlcd_display(uintnian,uintyue,uintri,uintshi,uintfen,uintmiao)
write_com(0x80);
delay();
write_date('
D'
);
A'
T'
E'
:
'
write_date(tab[nian/1000]);
write_date(tab[nian%1000/100]);
//delay();
write_date(tab[nian%1000%100/10]);
write_date(tab[nian%10]);
delay();
-'
//delay();
write_date(tab[yue/10]);
write_date(tab[yue%10]);
//delay();
write_date(tab[ri/10]);
//delay();
write_date(tab[ri%10]);
delay();
write_com(0xc0);
delay();
I'
M'
'
write_date(tab[shi/10]);
write_date(tab[shi%10]);
delay();
write_date(tab[fen/10]);
write_date(tab[fen%10]);
write_date(tab[miao/10]);
write_date(tab[miao%10]);
voidk1_button()
if(!
k1)
delay5ms(10);
while(!
k1);
if(c==1)
sec++;
if(sec==60)
sec=0;
if(c==2)
if(c==3)
hour++;
if(hour==24)
hour=0;
if(c==4)
day++;
if(day==32)
day=0;
if(c==5)
mon++;
if(mon==13)
mon=0;
if(c==6)
year++;
voidk2_button()
k2)
while(!
k2);
delay5ms(10);
if(c==1)
if(sec>
0)
sec--;
if(c==2)
if(min>
min--;
if(c==3)
if(hour>
hour--;
if(c==4)
if(day>
day--;
if(c==5)
if(mon>
mon--;
if(c==6)
if(year>
2012)
year--;
}
voidk3_button()
k3)
k3);
TR0=0;
c++;
while
(1)
if(!
delay5ms(10);
while(!
c++;
sec_init();
switch(c)
case1:
write_com(0xcc);
write_date(tab[sec/10]);
write_date(tab[sec%10]);
k1_button();
k2_button();
break;
case2:
write_com(0xc9);
write_date(tab[min/10]);
write_date(tab[min%10]);
k1_button();
break;
case3:
write_com(0xc6);
write_date(tab[hour/10]);
write_date(tab[hour%10]);
case4:
write_com(0x8d);
write_date(tab[day/10]);
write_date(tab[day%10]);
case5:
write_com(0x8a);
write_date(tab[mon/10]);
write_date(tab[mon%10]);
case6:
write_com(0x85);
write_date(tab[year/1000]);
write_date(tab[year%1000/100]);
write_date(tab[year%1000%100/10]);
write_date(tab[year%10]);
case7:
TR0=1;
c=0;
if(c==0)
write_com(0x0c);
}
/*voidinit0()
IT0=1;
IE0=1;
EX0=1;
voidexter0()interrupt0
lcd_init();
lcd_display(colock_year,colock_yue,colock_ri,colock_hour,colock_min,colock_sec);
k3_button(colock_year,colock_yue,colock_ri,colock_hour,colock_min,colock_sec);
voidclock()
if(colock_year==year&
colock_yue==mon&
colock_ri==day&
colock_hour==hour&
colock_min==min)
beep=~beep;
}*/
voidmain()
init_time0();
while
(1)
display();
lcd_display(year,mon,day,hour,min,sec);
if(!
k3_button();
}
电路图: