现在是按下key1后出现上面的情况,其他几个按键也一样。我现在想实现只有前5次按下开关会显示,以后按下都没有反应,程序改怎样修改
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^0;
sbit wela=P2^1;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8};//共阳极
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit key5=P1^4;
sbit key6=P1^5;
sbit start=P1^6;
sbit beep=P2^2;
uchar num=0;
uchar count=0;
uchar second=5;
uchar t;
uchar a=0;
uchar n=0;
//延时子函数
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
if(key1==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[1];
dula=0;
delayms(5);
}
if(key2==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[2];
dula=0;
delayms(5);
}
if(key3==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[3];
dula=0;
delayms(5);
}
if(key4==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[4];
dula=0;
delayms(5);
}
if(key5==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[5];
dula=0;
delayms(5);
}
if(key6==0)
{
beep=0;
wela=1;
P0=0x3f;
wela=0;
P0=0xff;
dula=1;
P0=table[6];
dula=0;
delayms(5);
}
}
main()
{
display();
}
|