朋友给我一个矩阵键盘行列扫描的程序,中间键盘扫描程序是这样的
unsigned char keyscan(void)
{
unsigned char val;
keyport=0xf0;
if(keyport!=0xf0)
{
delay2(10);
if(keyport!=0xf0)
{
keyport=0xfe;
if(keyport!=0xfe)
{
val=keyport&0xf0;
val+=0x0e;
while(keyport!=0xfe)
delay2(10);
while(keyport!=0xfe)
return val;
请问有谁能帮我详细解读一下这段程序里面各句的意思吗? 我自己看了一上午都没看明白是怎么扫描的。。。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
具体要求是通过矩阵键盘输入 然后在单个共阳数码管上输出,源程序是这样的#include<reg52.h>
#define dateport P1
#define keyport P3
unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char keyscan(void);
unsigned char keypro(void);
void delay1(unsigned char t);
void delay2(unsigned char t);
void main(void)
{
while(1)
{
switch(keypro())
{
case 0:P1=table[0];break;
case 1:P1=table[1];break;
case 2:P1=table[2];break;
case 3:P1=table[3];break;
case 4:P1=table[4];break;
case 5:P1=table[5];break;
case 6:P1=table[6];break;
case 7:P1=table[7];break;
case 8:P1=table[8];break;
case 9:P1=table[9];break;
case 10:P1=table[10];break;
case 11:P1=table[11];break;
case 12:P1=table[12];break;
case 13:P1=table[13];break;
case 14:P1=table[14];break;
case 15:P1=table[15];break;
default:break;
}
}
}
void delay1(unsigned char t)
{
while(t--);
}
void delay2(unsigned char t)
{
while(t--)
{
delay1(245);
delay1(245);
}
}
unsigned char keyscan(void)
{
unsigned char val;
keyport=0xf0;
if(keyport!=0xf0)
{
delay2(10);
if(keyport!=0xf0)
{
keyport=0xfe;
if(keyport!=0xfe)
{
val=keyport&0xf0;
val+=0x0e;
while(keyport!=0xfe);
delay2(10);
while(keyport!=0xfe);
return val;
}
keyport=0xfd;
if(keyport!=0xfd)
{
val=keyport&0xf0;
val+=0x0d;
while(keyport!=0xfd);
delay2(10);
while(keyport!=0xfd);
return val;
}
keyport=0xfb;
if(keyport!=0xfb)
{
val=keyport&0xf0;
val+=0x0b;
while(keyport!=0xfb);
delay2(10);
while(keyport!=0xfb);
return val;
}
keyport=0xf7;
if(keyport!=0xf7)
{
val=keyport&0xf0;
val+=0x07;
while(keyport!=0xf7)
delay2(10);
while(keyport!=0xf7)
return val;
}
}
}
return 0xff;
}
unsigned char keypro(void)
{
switch(keyscan())
{
case 0x7f:return 0;break;
case 0x7d:return 1;break;
case 0x7b:return 2;break;
case 0x77:return 3;break;
case 0xbe:return 4;break;
case 0xbd:return 5;break;
case 0xbb:return 6;break;
case 0xb7:return 7;break;
case 0xde:return 8;break;
case 0xdd:return 9;break;
case 0xdb:return 10;break;
case 0xd7:return 11;break;
case 0xee:return 12;break;
case 0xed:return 13;break;
case 0xeb:return 14;break;
case 0xe7:return 15;break;
default: return 0xff;break;
}
}
但是我运行之后发现好像有问题,就是有几个键按了之后没反应,但问题具体在哪儿我还没搞明白。一起看看咯
一周热门 更多>