请大家帮忙给看看,我这个矩阵键盘哪里有问题,不知道为啥,有时候要多按几下才会有反应,绝非键盘问题。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar aa;
uchar code ss[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e};
sbit FMQ=P1^5;
sbit SMG1=P1^0;
sbit SMG2=P1^1;
sbit SMG3=P1^2;
sbit SMG4=P1^3;
void display(uchar aa);
uchar keysun();
void delay(uint z);
void main()
{
aa=0;
SMG1=0;
SMG2=0;
SMG3=0;
SMG4=0;
while(1)
{
display(keysun());
}
}
void display(uchar aa)
{
P0=ss[aa];
}
uchar keysun()
{
uchar key,temp;
P2=0xfe;
temp=P2;
while(temp!=0xf0)
{
delay(1);
temp=P2;
while(temp!=0xf0)
{
switch(temp)
{
case 0xee: key=1; FMQ=0; break;
case 0xde: key=2; FMQ=0; break;
case 0xbe: key=3; FMQ=0; break;
case 0x7e: key=4; FMQ=0; break;
}
while(temp!=0xf0)
{
delay(1);
temp=P2;
temp=temp&0xf0;
}
}
FMQ=1;
display(key);
}
return key;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>