AT98C51单片机数码管显示0.0秒到9.9秒循环计时C语言程序

高手在线求帮请讲解下,AT98C51单片机数码管显示0.0秒到9.9秒循环计时C语言程序
最新回答
空有一颗爱她的`心

2024-07-01 14:00:03

#include<reg51.h>
#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//0-9
unsigned char times=0,sec=0,sec01,scanled;
unsigned char disdat[2];
void dischg()
{
disdat[0]=sec01;
disdat[1]=sec;
}
void t0isr() interrupt 1 //秒计时
{
TR0=0;
TH0=0x3c;
TL0=0xb0;
TR0=1;
times++;
if(times>=2)
{
times=0;
sec01++;
if(sec01>=10)
{
sec01=0;
sec++;
if(sec>=10)sec=0;
}
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TR1=0;
TH1=0xec;
TL1=0x78;
TR1=1;
switch(scanled)
{
case 0:
P2=~0x01;
P0=ledtab[disdat[5]];
break;
case 1:
P2=~0x02;
P0=ledtab[disdat[4]];
break;
default:break;
}
scanled++;
scanled%=2;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
EA=1;
TR1=1;
ET0=1;
ET1=1;
sec=0;
scanled=0;
dischg();
while(1);
}