#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar num,dunum,wenum;
uchar code table_du[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
                    0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code table_we[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
display();
void main()
{
	EA=1;
	ET0=1;
	TMOD=0X01;
	TH0=(65536-500)/256;   //给定时器0装初值，12M晶振定时时间为0.5ms
	TL0=(65536-500)%256;
	TR0=1;
	while(1)
	{
		if(num==2)   //如果到了2次，说明1ms时间到了
		{
			num=0;
			if(dunum==6)
			dunum=0;
			if(wenum==6)
			wenum=0;
			display();   //数码管显示
			dunum++;
			wenum++;
		}
	}
}

void time0() interrupt 1 
{
	TH0=(65536-500)/256;   //重装初值，12M晶振隔间0.5ms重装一次
	TL0=(65536-500)%256;
num++;     //每中断一次，num的值加1
}

display()   //数码管显示函数
{
	P0=0xff;       //关闭所有数码管显示，防止有交替重影，专业名称叫（消隐）
	wela=1;
	wela=0;

	P0=table_du[dunum+1];  //送入数码管段选值
	dula=1;
	dula=0;

	P0=table_we[wenum];  //送入数码管位选值
	wela=1;
	wela=0;
}