#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
sbit p23=P2^3;
uint counth,countl,countq,countb;
uint code tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0XFF,0X0C};
uint G;
void delay(void)
{
uint i;
for(i=0;i<230;i++);
}
void it0(void) interrupt 0 using 1 //加1中断
{
count++;
if(count==10000)
{
count=9999;
}
}
void it2(void) interrupt 2 using 2
{
if(count!=0)
{
count--;
}
}
void main()
{
G = 0;
P0 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
//
IT0 = 1; //中断初始化
IT1 = 1;
EA = 1;
EX0 = 1;
EX1 = 1;
PX1 = 1;
while(1) //0到9999的显示
{
countq = (count%10000)/1000; //千位
countb = (count%1000)/100; //百位
counth = (count%100)/10; //十位
countl = count%10;//个位
P0 = tab[countq];
p23 = 1;
delay();
p23 = 0;
P0 = tab[countb];
p22 = 1;
delay();
p22 = 0;
P0 = tab[countl];
p21 = 1;
delay();
p21 = 0;
P0=tab[counth];
p20 = 1;
delay();
p20 = 0;
}
}