0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0X40};
u8 yi,er,san,si,wu,liu,qi,ba;
u8 wendumax,wendumin;
u8 shezhicishu;
u8 qujian;
u16 dingshijian,yushijian;
u8 gongzuocanshu;
u8 shuzhi[4]={3,0,2,0};
u8 yudingwei;
void Timer0Init(void) //1??@11.0592MHz
{
ET0=1;
EA=1;
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0xCD; //??????
TH0 = 0xD4; //??????
TF0 = 0; //??TF0??
TR0 = 1; //???0????
} void Delay1ms() //@11.0592MHz
{ unsigned char i, j; _nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
} void allinit()
{
P2=0x80;
P0=0xff;
P2=0xa0;
P0=0x00;
} void display()
{
TR0=1;
P2=0xc0;
P0=0x01;
P2=0xff;
P0=~duan[yi];
Delay1ms();
P2=0xc0;
P0=0x02;
P2=0xff;
P0=~duan[er];
Delay1ms();
P2=0xc0;
P0=0x04;
P2=0xff;
P0=~duan[san];
Delay1ms();
P2=0xc0;
P0=0x08;
P2=0xff;
P0=~duan[si];
Delay1ms();
P2=0xc0;
P0=0x10;
P2=0xff;
P0=~duan[wu];
Delay1ms();
P2=0xc0;
P0=0x20;
P2=0xff;
P0=~duan[liu];
Delay1ms();
P2=0xc0;
P0=0x40;
P2=0xff;
P0=~duan[qi];
Delay1ms();
P2=0xc0;
P0=0x80;
P2=0xff;
P0=~duan[ba];
Delay1ms();
P2=0x80;
if(yudingwei==0)
{
P0=0xfe;
}
else
{
P0=0xff;
}
P2=0x00;
Delay1ms();
} void juzhen()
{
u8 dat,temp;
dat=17;
P3=0x7f;P4=0xef;
temp=P3;
temp&=0x0f;
if(temp!=0x0f)
{
Delay1ms(); temp=P3;
temp&=0x0f;
if(temp!=0x0f)
{
temp=P3;
switch(temp)
{
case 0x7e:dat=0;break;
case 0x7d:dat=3;break;
case 0x7b:dat=6;break;
case 0x77:dat=9;break;
}
while(temp!=0x0f)
{
temp=P3&0x0f;
}
}
}
P3=0xbf;P4=0xfb;
temp=P3;
temp&=0x0f;
if(temp!=0x0f)
{Delay1ms();
temp=P3;
temp&=0x0f;
if(temp!=0x0f)
{
temp=P3;
switch(temp)
{
case 0xbe:dat=1;break;
case 0xbd:dat=4;break;
case 0xbb:dat=7;break;
case 0xb7:dat=10;break;
}
while(temp!=0x0f)
{
temp=P3&0x0f;
}
}
}
P3=0xdf;
temp=P3;
temp&=0x0f;
if(temp!=0x0f)
{
temp=P3;
temp&=0x0f;
Delay1ms();
if(temp!=0x0f)
{
temp=P3;
switch(temp)
{
case 0xde:dat=2;break;
case 0xdd:dat=5;break;
case 0xdb:dat=8;break;
case 0xd7:dat=11;break;
}
while(temp!=0x0f)
{
temp=P3&0x0f;
}
}
}
if(gongzuocanshu==1&&dat!=17&&dat!=10)
{
shuzhi[shezhicishu]=dat;
shezhicishu+=1;
}
if(dat==10)
{
gongzuocanshu+=1;
}
if(gongzuocanshu==2)
{
gongzuocanshu=0;
} if( gongzuocanshu==1)
{
if(dat==11)
{
shezhicishu=0;
shuzhi[0]=0;
shuzhi[1]=0;
shuzhi[2]=0;
shuzhi[3]=0;
}
}
}
void wenduxianshi()
{
yi=17;er=qujian;san=17;si=16;wu=16;liu=16;
qi=zuizhong()/10%10;
ba=zuizhong()%10;
if((qi*10+ba)>wendumax)
{
qujian=2;
yushijian=200;
}
if((qi*10+ba)<wendumin)
{
qujian=0;
yushijian=800;
}
if((qi*10+ba)>wendumin&&(qi*10+ba)<wendumax)
{
qujian=1;
yushijian=400;
}
}
void gongzuocanshushezhi()
{
yi=17;er=wendumax/10;san=wendumax%10;si=16;wu=16;liu=17;
qi=wendumin/10;ba=wendumin%10;
} void main()
{
Timer0Init();
allinit();
while(1)
{
if(qujian==2)
{
P2=0xa0;
P0=0x10;
P2=0x00;
}
else
{
P2=0xa0;
P0=0x00;
}
juzhen();
wendumax=shuzhi[0]*10+shuzhi[1];
wendumin=shuzhi[2]*10+shuzhi[3];
if(gongzuocanshu>0)
{
P2=0xc0;
TR0=0;
gongzuocanshushezhi();
if(wendumax<wendumin)
{
P2=0x80;
P0=0xfd;
P2=0x00;
}
}
else{
TR0=1;
P2=0x80;
P0=0xff;
P2=0x00;
wenduxianshi();
shezhicishu=0;
}
display();
}
}
void ding()interrupt 1
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0;
dingshijian++;
if(dingshijian==yushijian)
{
dingshijian=0;
yudingwei=~yudingwei;
} }