#include
#define uchar unsigned char
#define uint unsigned int
unsigned char code ledChar[]=
{
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, //CA数码管编码
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E
};
unsigned char ledBuff[2]=
{
0xFF, 0xFF //初始化数码管
};
uint count=0;
uint x=0;
uint time1=15;
uint time2=20;
Ledshow()
{
if(x == 0)
{
if(time1 >=0)
{
P1 = 0x0c;
}
}
if(x == 1)
{
if(time1>=0)
{
P1 = 0x0a;
}
}
if(x == 2)
{
if(time1>=5)
{
P1 = 0x21;
}
if (time1=5)
{
P1 = 0x0A;
}
}*/
void delay(uint x)
{ uchar i;
while(x--)
for(i=0;i<120;i++);
}
void display()
{
ledBuff[0]=ledChar[time1/10];
ledBuff[1]=ledChar[time1];
P2=0x01;
P0=ledBuff[0];
delay(1);
P2=0x02;
P0=ledBuff[1];
delay(1);
ledBuff[0]=ledChar[time2/10];
ledBuff[1]=ledChar[time2];
P2=0x04;
P0=ledBuff[0];
delay(1);
P2=0x08;
P0=ledBuff[1];
delay(1);
Ledshow();
}
void main()
{
TMOD=0x01;
TH0=0x3C;
TL0=0xb0;
TR0=1;
EA=1;
ET0=1;
while(1)
{
display();
}
}
void in_TR0() interrupt 1
{
TH0=0x3c; //重新赋初值
TL0=0xb0;
count++;
if (count==20) //我们定义的是1ms中断,要一秒变化一次,让count加到1000
{
count=0; //到1000后重新赋初值
time1--;
time2--;
if(x == 0 && time1 == 0)
{
time1=5;
x = 1;
}
if(x == 1 && time1 == 0)
{
time1=20;
time2=15;
x = 2;
}
if(x == 2 && time1 ==5)
{
time2=5;
x = 2;
}
if(x == 2 && time1 ==0)
{
time1=15;
time2=20;
x = 0;
}
}
}
1