微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 八路抢答器30秒倒计时计时不正常求教

八路抢答器30秒倒计时计时不正常求教

时间:10-02 整理:3721RD 点击:
我在做一个8路抢答器的课程设计,设置的抢答倒计时时间为30S,可是按下启动按钮之后大概要经过10S才由30秒变为29秒,然后再经过10S变成28秒,这是怎么回事啊?
下面是我的C语言源程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit k0=P1^0;
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;
sbit k4=P1^4;
sbit k5=P1^5;
sbit k6=P1^6;
sbit k7=P1^7;
sbit we1a0=P2^0;
sbit we1a1=P2^2;
sbit we1a2=P2^3;
sbit beep=P2^4;
sbit ks=P3^0;
sbit tz=P3^1;
sbit jiayi=P3^4;
sbit jianyi=P3^5;
sbit fw=P3^6;
uchar qiangdanum=0xff;
uchar code table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar ge=0,shi=0;
uint num,time=30;
void display();
void kys();
void kys2();
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void intial()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
}
main()
{
intial();
while(1)
{
display();
kys();
if(TR0==1)
{
kys2();
}
}
}
void kys2()
{
if(k0==0)
{
delay(5);
if(k0==0)
{
qiangdanum=1;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k1==0)
{
delay(5);
if(k1==0)
{
qiangdanum=2;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k2==0)
{
delay(5);
if(k2==0)
{
qiangdanum=3;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
qiangdanum=4;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k4==0)
{
delay(5);
if(k4==0)
{
qiangdanum=5;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k5==0)
{
delay(5);
if(k5==0)
{
qiangdanum=6;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k6==0)
{
delay(5);
if(k6==0)
{
qiangdanum=7;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
if(k7==0)
{
delay(5);
if(k7==0)
{
qiangdanum=8;
beep=1;
delay(100);
beep=0;
TR0=0;
time=60;
}
}
}
void kys()
{
if(ks==0)
{
delay(5);
if(ks==0)
{
TR0=1;
}
}
if(tz==0)
{
delay(5);
if(tz==0)
TR0=0;
}
if(jiayi==0)
{
delay(5);
if(jiayi==0)
time++;
while(!jiayi);
}
if(jianyi==0)
{
delay(5);
if(jianyi==0)
time--;
while(!jianyi);
}
if(fw==0)
{
delay(5);
if(fw==0)
{
time=30;
qiangdanum=0xff;
}
}
}
void time0() interrupt 1
{
num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(num==200)
{
num=0;
time--;
if(time==0)
{
time=1;
TR0;
}
}
}
void display(void)
{
shi=time/10;
ge=time%10;
P2=0xf7;
P0=table[ge];
delay(5);
P2=0xfb;
P0=table[shi];
delay(5);
P2=0xfe;
P0=table[qiangdanum];
delay(5);
}

问题已经解决  是我的程序出了点问题

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top