51单片机数码管九秒倒计时程序

要可以在单片机上实现九秒倒计时的

第1个回答  2019-10-17
#include<reg51.h>
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
uchar num=9;
uchar cnt;
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
while(1)
{
if(key==0)
{
while(key==0);
num=9;
}
P0=table[num];
}
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
cnt++;
if(cnt>=20)
{
cnt=0;
if(num>0)num--;
}
}本回答被网友采纳