#include<reg51.h>
#define unchar unsigned char
unchar DispTab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unchar i;
unchar count=0;
void timer0 (void) interrupt 1
{
TH0=-50000/256;
TL0=-50000%256;
i++;
if (i==2)
{
i=0;
count--;
}
if (count==0)
{
count=110;
}
P0=DispTab[count/100];
P2=DispTab[(count%100)/10];
P1=DispTab[count%10];
}
void main ( )
{
TMOD=0x01;
TH0=-50000/256;
TL0=-50000%256;
P0=DispTab[count/100];
P2=DispTab[(count%100)/10];
P1=DispTab[count%10];
EA=1;
ET0=1;
TR0=1;
EX1=1; //外部中断0开
IT1=0; //0电平触发
EX0=1; //外部中断0开
IT0=0; //0电平触发
do{}while(1);
}
void ISR_Key(void) interrupt 0
{
TR0=~TR0; //进入中断程序执行程序,
}
void ISR_Key2(void) interrupt 2
{
//进入中断程序执行程序,
i=0;
count=0;
P0=0X06;
P2=0X3F;
P1=0x3f;
}
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面是仿真效果
-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/