求两位数码管显示一个倒数时间的单片机程序,比如显示从99到0

如题所述

//两位数码管显示倒计数99~00,51单片机
#include<reg52.h> // 倒计数
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar bai,shi;
uint a1,a2;
sbit D1=P3^0; // 位选1 P1口段码输出
sbit D2=P3^1; // 位选2
sbit key=P3^7; // 启动/停止
bit y ;
void main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
bai=0;
shi=0;
while(1)
{
if(key==0)
{
}
}
}
void timer0()interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
a1++;
y = ~y;
if(a1==100)
{
a1=0;
if(key==1) a2--;
if(a2>=100) a2=99;
}
D1 = 1; D2 = 1;
if(y==1)
{
P1=table[a2/10];
D1=0;
}
else
{
P1=table[a2%10];
D2=0;
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-04-29
从60秒到30秒再到90秒并循环倒计时显示。
相似回答