定時(shí)器計(jì)數(shù)并將計(jì)數(shù)值實(shí)時(shí)顯示在數(shù)碼管
//********************************
//定時(shí)器T1計(jì)數(shù)并將計(jì)數(shù)值實(shí)時(shí)顯示至數(shù)碼管
//T0定時(shí)(數(shù)碼管動態(tài)掃描用);T1計(jì)數(shù)
//作者:曾憲陽
//網(wǎng)址: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;//關(guān)閉顯示
P0=Duan[Disp[x]];
P2=Wei[x];
x++;
if(x==5)x=0;
}
voidInitT0(void)
{
TMOD=0X51;//T0定時(shí)(動態(tài)掃描顯示);T1計(jì)數(shù)
TH0=(65536-1000)/256;
TL0=(65536-1000)%6;
EA=1;ET0=1;
TR0=1;TR1=1;
}
voidmain(void)
{
InitT0();
while(1)
{
i=0;//讀數(shù)前清零i
i=(((i"TH1)<<8)|TL1);//讀取T1的值至i
Disp[4]=i/10000;//拆分各位數(shù)據(jù)后保存至顯示緩沖區(qū)
Disp[3]=i000/1000;
Disp[2]=i00000/100;
Disp[1]=i000000/10;
Disp[0]=i000000;
}
}
評論