我感觉自己掌握的矩阵键盘扫描写法比较繁琐,希望有大佬指教好的方法,十分感谢!
uchar KeyScan() //带返回值的子函数
{
uchar cord_l,cord_h;//声明列线和行线的值的储存变量
P3 = 0xf0;//1111 0000
if( (P3 & 0xf0) != 0xf0)//判断是否有按键按下(按下就为与)
{
delay(5);//软件消抖
if( (P3 & 0xf0) != 0xf0)//再次判断是否有按键按下
{
cord_l = P3 & 0xf0;// 储存列线值
P3 = cord_l | 0x0f;
cord_h = P3 & 0x0f;// 储存行线值
while( (P3 & 0x0f) != 0x0f );//松手检测
return (cord_l + cord_h);//返回键值码
}
}
}
void KeyPro()
{
switch( KeyScan() )
{
//第一行键值码
case 0xee: P0 = leddata[0]; break;
case 0xde: P0 = leddata[1]; break;
case 0xbe: P0 = leddata[2]; break;
case 0x7e: P0 = leddata[3]; break;
//第二行键值码
case 0xed: P0 = leddata[4]; break;
case 0xdd: P0 = leddata[5]; break;
case 0xbd: P0 = leddata[6]; break;
case 0x7d: P0 = leddata[7]; break;
//第三行键值码
case 0xeb: P0 = leddata[8]; break;
case 0xdb: P0 = leddata[9]; break;
case 0xbb: P0 = leddata[10]; break;
case 0x7b: P0 = leddata[11]; break;
//第四行键值码
case 0xe7: P0 = leddata[12]; break;
case 0xd7: P0 = leddata[13]; break;
case 0xb7: P0 = leddata[14]; break;
case 0x77: P0 = leddata[15]; break;
}
}
一周热门 更多>