新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 動(dòng)態(tài)掃描方法和定時(shí)器1在數(shù)碼管的前三位顯示出秒表

動(dòng)態(tài)掃描方法和定時(shí)器1在數(shù)碼管的前三位顯示出秒表

作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏
/*

動(dòng)態(tài)掃描方法和定時(shí)器1在數(shù)碼管的前三位顯示出秒表
*/
#include
#include
#define uint unsigned int
#define uchar unsigned char
uint closedu,closewe;
uchar code wetable[]={
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};

本文引用地址:http://butianyuan.cn/article/201612/324160.htm

uchar code dutable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//段選

uint ge,shi,bai,num;
uchar wenum,count;

void delay(uint z);

void init();

void display(uint bai,uint shi,uint ge);

void main()
{
init();
while(1)
{
display(bai,shi,ge);
}
}

void init()
{
num=0;
count=0;
wenum=0;
closedu=0xff;
closewe=0xff;
P1=closewe;//關(guān)閉位選
P0=closedu;//關(guān)閉段選
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<110;y++)
{
}
}
}

void display(uint bai,uint shi,uint ge)
{
closedu=0xff;
closewe=0xff;
wenum=0;
P1=wetable[wenum];
P0=dutable[bai];
delay(1);
P1=closewe;
P0=closedu;
wenum++;
P1=wetable[wenum];
P0=dutable[shi];
delay(1);
P1=closewe;
P0=closedu;
wenum++;
P1=wetable[wenum];
P0=dutable[ge];
delay(1);
P1=closewe;
P0=closedu;
wenum=0;
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
num++;
if(num==1000)
{
num=0;
}
bai=num/100;
shi=num%100/10;
ge=num%10;
}
}



評(píng)論


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

關(guān)閉