void display(char shi ,char ge );
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82
,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e} ;
sbit DUAN=P2^6;
sbit WEI=P2^7;
char shi,ge,num0,num;
void delayms( int xms);
void main()
{ TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1; //打开总中断
ET0=1; //打开定时器0中断
TR0=1; //启动定时器0中断
while(1)
{
display(shi,ge);
}
}
void display(char shi,char ge)
{ DUAN=1;
P0=table[shi];
DUAN=0;
P0=0xff;
WEI=1;
P0=0x01;
WEI=0;
delayms(5);
DUAN=1;
P0=table[ge];
DUAN=0;
P0=0xff;
WEI=1;
P0=0x02;
WEI=0;
delayms(5);
}
void delayms( int xms)
{ int i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{ num0=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;
}
}