//********************************
//守时器T1计数并将计数值实时显现至数码管
//T0守时(数码管动态扫描用);T1计数
//作者:曾宪阳
//网址:http://hi.baidu.com/zxymcu
//********************************
#include
#defineucharunsignedchar
#defineuintunsignedint
unsignedinti=0;
ucharx=0;
ucharcodeDuan[]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
ucharcodeWei[]={0x01,0X02,0X04,0x08,0x10,0X20};
ucharDisp[5];
voidTime0(void)interrupt1using3
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%6;
P2=0X00;//封闭显现
P0=Duan[Disp[x]];
P2=Wei[x];
x++;
if(x==5)x=0;
}
voidInitT0(void)
{
TMOD=0X51;//T0守时(动态扫描显现);T1计数
TH0=(65536-1000)/256;
TL0=(65536-1000)%6;
EA=1;ET0=1;
TR0=1;TR1=1;
}
voidmain(void)
{
InitT0();
while(1)
{
i=0;//读数前清零i
i=(((i”TH1)<<8)|TL1);//读取T1的值至i
Disp[4]=i/10000;//拆分各位数据后保存至显现缓冲区
Disp[3]=i000/1000;
Disp[2]=i00000/100;
Disp[1]=i000000/10;
Disp[0]=i000000;
}
}