求单片机倒计时程序
发布网友
发布时间:2022-04-25 01:24
我来回答
共2个回答
热心网友
时间:2023-10-19 10:39
#include<reg51.h>
#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9
unsigned char scanled;
unsigned char time;
unsigned char disdat[6];
int sec=9856;
void dischg()
{
disdat[0]=1;
disdat[1]=2;
disdat[2]=sec/1000;
disdat[3]=sec%1000/100;
disdat[4]=sec%100/10;
disdat[5]=sec%10;
}
void t0isr() interrupt 1//秒计时
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
sec--;
if(sec==0)TR0=0;
}
dischg();
}
void t1isr() interrupt 3//显示
{
TH1=0xec;
TL1=0x78;
P2=~(1<<scanled);
P0=ledtab[disdat[scanled]];
scanled++;
scanled%=6;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
dischg();
while(1);
}追问这个倒计时不了?
热心网友
时间:2023-10-19 10:39
可以哦
私信联系吧
仿真很直观的