我是用C语言做的调试了还行;基本上和你的要求差不多;不过用的是共阴管子参考下吧;
#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^0;
sbit wela=P2^1;
sbit s1=P1^0;
sbit s2=P1^1;
uchar t;
uint a=9999;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void display(uchar aa,uchar bb,uchar cc,uchar dd);
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
TR0=0; //进来不打开定时器
ET0=1;
while(1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
while(!s1);
TR0=1;//开定时器
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
TR0=0;//关定时器;
}
}
display(a/1000,a%1000/100,b%100/10,b%10);
}
}
void timer0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
t++;
if(t==1)
{
t=0;
a++;
if(a==10000)
a=0;
}
}
void display(uchar aa,uchar bb,uchar cc,uchar dd)
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[aa];
dula=0;
delay(5);
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[bb];
dula=0;
delay(5);
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[cc];
dula=0;
delay(5);
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
dula=1;
P0=table[dd];
dula=0;
delay(5);
P0=0xff;
}