按下P33所对应的的按键后,出正确现象;再按P32所对应的按键,也出正确现象;可是再按P33所对应的的按键数码管显示的数字就不走了,然后怎么按数码管数据都不变。
#include<reg52.h>
sbit P30=P3^0;
sbit P31=P3^1;
sbit P32=P3^2;
sbit P33=P3^3;
void delayms(int b);
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,};
unsigned char n,tt,k=0;
void keyscan();
void delayms(int b)
{int i;
long a;
for(i=b;i>0;i--)
{
for(a=110;a>0;a--);
}
}
void main()
{
P2=0xa0;P0=0x00;P2=0x80;P0=0xff;P2=0xc0;P0=0xff;P2=0xff;P0=0xc0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TF0=0;
EA=1;
ET0=1;
while(1)
{
keyscan();
}
}
void keyscan()
{
if(P33==0)
{
delayms(5);
if(P33==0)
{
n=1;
TR0=1;
}
while(!P33);
}
else if(P32==0)
{
delayms(5);
if(P32==0)
{
n=2;
TR0=1;
}
while(!P32);
}
}
void Timer0() interrupt 1
{
tt++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(n==1)
{
if(tt==5)
{
tt=0;
P0=tab[k];
k++;
if(k==16)k=0;
}
}
if(n==2)
{
if(tt==20)
{
tt=0;
P0=tab[k];
k++;
if(k==16)k=0;
}
}
}