include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=100;
uchar time=0;
//***陰數碼管七段碼
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延時程序
{
uint j;
for(;i>0;i--)
{
for(j=0;j<164;j++)
{;}
}
}
void main(void )//主程序
{
TMOD=0X01;
ET0=1;
EA=1;
TH0=(65536-50000)/256;//定時50ms
TL0=(65536-50000)%256;
TR0=1;
while(1)
{
P0=table[num/10];
Delay1ms(2);
P2=table[num%10];
Delay1ms(2);
}
}
void TIMER0()interrupt 1//中斷程序
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
if(time==20)
{
time=0;
num--;
}
if(num==0)
{
num=100;
}
}