单片机简答题 以4×4矩阵键盘为例,写出该键盘按键处理扫描流程

如题所述

uchar kbscan(void)
{
unsigned char sccode,recode;
P1=0x0f; //发0扫描,列线输入
if ((P2 & 0x0f) != 0x0f) //有键按下
{
delay(20); //延时去抖动
if ((P1&0x0f)!= 0x0f)
{
sccode = 0xef; //逐行扫描初值
while((sccode&0x01)!=0)
{
P1=sccode;
if((P1&0x0f)!=0x0f)
{
recode=(P1&0x0f)|0xf0;
while((P1&0x0f)!=0x0f);//等待键抬起
return((~sccode)+(~recode));
}
else
sccode=(sccode<<1)|0x01;
}
}
}
return 0; //无键按下,返回0
}
温馨提示:答案为网友推荐,仅供参考
相似回答