#include
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^0;
sbit lcden=P3^1;
sbit s1=P3^6;
sbit s2=P3^7;
uchar count,shi,fen,miao,num;
uchar code table[]=”2011-02-25″;
uchar code table1[]=”00:00:00″;
void reflesh(uchar add,uchar date);
void delay(uchar z)
{
uint x,y;
for(x=0;xfor(y=0;y<110;y++);
}
void write_ins(uchar add)
{
rs=0;
delay(5);
P1=add;
lcden=1;
delay(5);
lcden=0;
delay(5);
}
void write_date(uchar add)
{
rs=1;
delay(5);
P1=add;
lcden=1;
delay(5);
lcden=0;
delay(5);
}
void init()
{
uchar i;
lcden=0;
shi=0;
fen=0;
miao=0;
write_ins(0x38);
write_ins(0x0c);
write_ins(0x06);
write_ins(0x01);
write_ins(0x80);
for(i=0;i<14;i++)
{
write_date(table[i]);
delay(5);
}
write_ins(0x80+0x40);
for(i=0;i<13;i++)
{
write_date(table1[i]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(num==””||num==0)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
TR0=0;
write_ins(0x80+0x40+11);
write_ins(0x0c);
num=1;
}
}
if(num==1)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x80+0x40+8);
write_ins(0x0c);
num=2;
}
}
if(num==2)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x80+0x40+5);
write_ins(0x0c);
num=3;
}
}
if(num==3)
{
if(s1==0)
delay(5);
if(s1==0)
{
while(!s1);
write_ins(0x0c);
TR0=1;
num=0;
}
}
if(num!=0)
{
if(num==1)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
miao++;
if(miao==60)
miao=0;
reflesh(0x80+0x40+10,miao);
}
}
if(num==2)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
fen++;
if(fen==60)
miao=0;
reflesh(0x80+0x40+7,fen);
}
}
if(num==3)
{
if(s2==0)
delay(5);
if(s2==0)
{
while(!s2);
shi++;
if(shi==24)
shi=0;
reflesh(0x80+0x40+4,shi);
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
}
reflesh(0x80+0x40+4,shi);
}
reflesh(0x80+0x40+7,fen);
}
reflesh(0x80+0x40+10,miao);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
count++;
}
void reflesh(uchar add,uchar date)
{
uchar ten,ge;
write_ins(add);
ten=date/10;
ge=date;
write_date(0x30+ten);
write_date(0x30+ge);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/chuanganqi/257951.html