#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED0=P1^0;
sbit LED1=P1^1;
sbit LED2=P1^2;
sbit LED3=P1^3;
sbit d1=P0^0;
sbit d2=P0^1;
sbit d3=P0^2;
sbit d4=P0^3;
sbit Btton=P3^2;
char timedao1;
char timedao2;
code unsigned char table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
/***********************
***********************/
void delayms(xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void Display()
{
char h,l;
h=timedao1/10;
l=timedao1%10;
d1=1;
d2=0;
d3=1;
d4=1;
P2=table[h];
P2=table[l];
delayms(10);
d2=1;
d1=0;
h=timedao2/10;
l=timedao2%10;
P2=table[h];
delayms(2);
d3=1;
d4=1;
P2=table[h];
delayms(2);
d4=1;
}
void timer0(void)interrupt 1 using 1
{
static uchar count;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
if(timedao1>=0)
timedao1--;
if(timedao2>=0)
timedao2--;
count=0;
}
}
void main()
{
int c;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
EX0=1;
IT0=1;
TR0=1;
while(1)
{
timedao1=9;
timedao2=4;
while(timedao1>=0)
{
LED3=0;
LED0=0;
Display();
}
for(c=0;c<11;c++)
{
LED3=~LED3;
LED0=~LED0;
delayms(1000);
}
timedao1=9;
timedao2=4;
while(timedao1>=0)
{
LED2=0;
LED1=0;
Display();
}
for(c=0;c<11;c++)
{
LED1=~LED1;
LED2=~LED2;
delayms(1000);
}
}
}