请大神帮我检查下矩阵键盘程序哪里出错了
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint z);
void display(uchar a);
uchar keyscan();
uchar n,i;
uchar code table[]=
{
0xc0, 0xf9, 0xa4, 0xb0, 0x99,
0x92, 0x82, 0xf8, 0x80, 0x90, 0xff
}
void main()
{
i=17;
P2=0x00;
while(1)
{
display(keyscan());
}
}
uchar keyscan()
{
P1=0xfe;
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
delay(10);
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
n=P1;
switch(n)
{
case 0x7e:i=1;
break;
case 0xbe:i=2;
break;
case 0xde:i=3;
break;
case 0xee:i=4;
break;
}
}
}
P1=0xfd;
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
delay(10);
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
n=P1;
switch(n)
{
case 0x7d:i=1;
break;
case 0xbd:i=2;
break;
case 0xdd:i=3;
break;
case 0xed:i=4;
break;
}
}
}
P1=0xfb;
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
delay(10);
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
n=P1;
switch(n)
{
case 0x7b:i=1;
break;
case 0xbb:i=2;
break;
case 0xdb:i=3;
break;
case 0xeb:i=4;
break;
}
}
}
P1=0xf7;
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
delay(10);
n=P1;
n=n&0xf0;
while(n!=0xf0)
{
n=P1;
switch(n)
{
case 0x77:i=1;
break;
case 0xb7:i=2;
break;
case 0xd7:i=3;
break;
case 0xe7:i=4;
break;
}
}
}
return i;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar a)
{
P0=table[a-1];
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>