本帖最后由 ty1649 于 2013-9-24 21:44 编辑
#include
#define unit unsigned int
#define uchar unsigned char
uchar duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unit zhong[2][8]={0,0,10,0,0,10,2,1,1,0,10,1,0,10,3,1};
uchar j,t,second,keytime0,i,m,shan,keytime2,minute,day=1,mon=1,year=13,hour=12;
***it K0=P1^0;
***it K1=P1^1;
***it K2=P1^2;
***it K3=P1^3;
unit a,b;
void delayms(unit n)
{
while(n--)
for(b=0;b<100;b++);
}
void keybox0()
{
keytime0=(keytime0+1)%3;
switch(keytime0)
{
case 1: ET0=1;EA=1;TR0=1;break;
case 2: TR0=0;EA=1;ET1=1;TR1=1;break;
case 0: EA=0;P0=0xff;break;
}
}
void keybox1()
{
keytime2++;
if(keytime2==4)
keytime2=0;
}
void keybox2()
{
if(keytime2!=0 && K3==0)
{
switch(keytime2)
{
case 1: if(i==0)
second++;
else
day++;break;
case 2: if(i==0)
minute++;
else
mon++;break;
case 3: if(i==0)
hour++;
else
year++;break;
}
}
}
void timer1()
{
if(a++==1000)
{
shan=!shan;
a=0;
second++;
if(second==60)
{
minute++;
second=0;
if(minute==60)
{
hour++;
minute=0;
if(hour==24)
{
hour=0;
day++;
if(day=(mon%2==0)? 30:31)
{
mon++;
day=0;
if(mon==12)
{
year++;
}
}
}
}
}
}
zhong[0][0]=second%10;
zhong[0][1]=second/10;
zhong[0][3]=minute%10;
zhong[0][4]=minute/10;
zhong[0][6]=hour%10;
zhong[0][7]=hour/10;
}
void timer0()
{
if(a++==1000)
{
second++;
shan=!shan;
a=0;
if(second==60)
{
minute++;
second=0;
if(minute==60)
{
hour++;
minute=0;
if(hour==24)
{
day++;
if(day==(mon%2==0)? 30:31)
{
mon++;
day=0;
if(mon==12)
{
year++;
mon=0;
}
}
}
}
}
}
zhong[1][0]=day%10;
zhong[1][1]=day/10;
zhong[1][3]=mon%10;
zhong[1][4]=mon/10;
zhong[1][6]=year%10;
zhong[1][7]=year/10;
}
void timer3() interrupt 3
{
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
P2=0;
P0=duan[zhong[j]];
P2=wei[j];
j++;
if(j==8)
j=0;
}
void timer() interrupt 1
{
m=0xff*shan;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
P2=0;
switch(keytime2)
{
case 1: if(j==1||j==0)
P0=m|duan[zhong[j]];
else
P0=duan[zhong[j]];break;
case 2:
if(j==3||j==4)
P0=m|duan[zhong[j]];
else
P0=duan[zhong[j]];break;
case 3: if(j==6||j==7)
P0=m|duan[zhong[j]];
else
P0=duan[zhong[j]];break;
case 0: P0=duan[zhong[j]];
}
P2=wei[j];
j++;
if(j==8)
j=0;
switch(i)
{
case 0: timer1();break;
case 1: timer0();break;
}
}
void main()
{
TMOD=0x11;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
while(1)
{
if(K0==0)
{
delayms(10);
keybox0();
while(K0==0);
}
if(K1==0)
{
delayms(10);
i=!i;
while(K1==0);
}
if(K2==0)
{
delayms(10);
keybox1();
while(K2==0);
}
if(K3==0)
{
delayms(10);
keybox2();
delayms(200);
}
}
}
|