题目:1.数码管前三位显示一个跑表,从000到999之间以1%秒速度运行,
当按下 一个独立键盘时跑表停止,松开手后跑表继续运行。(用定时器设计表)
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code duan[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar code wei[]={0xbe,0xbd,0xbb,0xb7};
uint tt,bb,flag,ge,shi,bai,qian,wan,temp,i,l,num,num1,num2;
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P3^4;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void
timer1() interrupt 3
{
TH1=(65535-10000)/256;
TL1=(65535-10000)%256;
bb++;
{
bb==1;
P2=0xbe;
P0=duan[bai];
delay(10);
P2=0xbd;
P0=duan[shi];
delay(10);
P2=0xbb;
P0=duan[ge];
delay(10);
}
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
tt++;
ge=temp%10;
shi=temp/10%10;
bai=temp/100;
if(tt==1)
{
tt=0;
P2=0xbe;
P0=duan[bai];
delay(10);
P2=0xbd;
P0=duan[shi];
delay(10);
P2=0xbb;
P0=duan[ge];
delay(10);
temp++;
if(temp==999)
{temp=0;}
}
}
void display()
{
P2=0xb8;
P0=duan[0];
}
void init ()
{
TMOD=0x11;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TH1=(65535-10000)/256;
TL1=(65535-10000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=0;
}
void main(void)
{
init();
display();
while(1)
{
if(key1==0) //停止
{
delay(7);
if(key1==0)
{
TR0=0;
TR1=1;
while(!key1);
delay(8);
while(!key1);
}
}
if(key2==0) //继续开始工作
{
delay(7);
if(key2==0)
{
TR0=1;
TR1=0;
while(!key1);
delay(8);
while(!key1);
}
}
if(key3==0) //清零
{
delay(7);
if(key3==0)
{
temp=0;
while(!key1);
delay(8);
while(!key1);
}
}
}
}
问题:当按下停止键后,确实是停止了,但按继续开始工作键和清零键都还是显示在停止的那个数值,我想应该是中断方面出了错。。求大神
哦,多谢指导,但是我想请问一下,为什么我这样写定时器的优先问题会不起作用,具体请看停止键{TR0=0;TR1=1;}和继续开始键的{TR0=1;TR1=0;},敢问问什么这里会有冲突??谢了
一周热门 更多>