新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 如何實(shí)現(xiàn)數(shù)碼管3位計(jì)數(shù)器

如何實(shí)現(xiàn)數(shù)碼管3位計(jì)數(shù)器

作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
利用兩個(gè)定時(shí)器 來實(shí)現(xiàn) 3位數(shù)碼管 同時(shí)顯示計(jì)時(shí)器, 即從0- 999范圍的計(jì)時(shí)
#include
//共陰極數(shù)碼管編碼范圍
unsigned char code table[10]={0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0xef };
unsigned char first=0;
unsigned char second=0;
unsigned char third=0;
unsigned int number=0;
unsigned char t=0;
void Delay()
{
unsigned char j;
unsigned char i;
for(i=10; i>0; i--)
for(j=110; j>0; j--);
}
void main()
{
TMOD=0x11; //設(shè)置兩個(gè)定時(shí)器T0,T1的工作方式: 使用16位寄存器的方式1
EA=1; //打開 全局中斷
ET0=1; // 打開定時(shí)器T0的中斷
ET1=1;
TR0=1; // 啟動(dòng)定時(shí)器T0
TR1=1;
TH0=(65536-50000)%256;
TL0=(65536-50000)%256;
TH1=(65536-50000)%256;
TL1=(65536-50000)%256;
while(1)
{
if(t==20)
{
t=0;
number++;
first=number/100;
second=(number-first*100)/10;
third=(number-first*100)%10;
}
}
}
void TimerLED0() interrupt 1 using 1
{
TH0=(65536-50000)%256;
TL0=(65536-50000)%256;
t++;
}
void TimerLED1() interrupt 3 using 2
{
TH1=(65536-10000)%256;
TL1=(65536-10000)%256;
P2=0xfe;
P0=table[first];
Delay();
P2=0xfd;
P0=table[second];
Delay();
P2=0xfb;
P0=table[third];
Delay();
}



評論


技術(shù)專區(qū)

關(guān)閉