单片机矩阵键盘如何输入多位数?程序
2个回答
展开全部
我不知道你用的是那种单片机 我这里有128的 你可以看看
DDRA = 0x00;/*获取列地址*/
PORTA = 0x0F;
DDRA = 0xF0;
delay_nms(20);//延时必须足够
k = PINA;
DDRA = 0x00;/*获取行地址*/
PORTA = 0xF0;
DDRA = 0x0F;
delay_nms(1);
k |= PINA;
DDRA = 0x00;/*输出复位*/
PORTA = 0xFF;
switch (k)
{/*将按键码转换成键值*/
case 0xEB: while((key_scan()) != 16);return 7;
case 0x77: while((key_scan()) != 16);return 13;
case 0x7B: while((key_scan()) != 16);return 12;
case 0x7D: while((key_scan()) != 16);return 11;
case 0xB7: while((key_scan()) != 16);return 14;
case 0xBB: while((key_scan()) != 16);return 9;
case 0xBD: while((key_scan()) != 16);return 6;
case 0xD7: while((key_scan()) != 16);return 0;
case 0xDB: while((key_scan()) != 16);return 8;
case 0xDD: while((key_scan()) != 16);return 5;
case 0x7E: while((key_scan()) != 16);return 10;
case 0xBE: while((key_scan()) != 16);return 3;
case 0xDE: while((key_scan()) != 16);return 2;
case 0xEE: while((key_scan()) != 16);return 1;
case 0xED: while((key_scan()) != 16);return 4;
case 0xE7: while((key_scan()) != 16);return 15;
default : return 16; //无键按下
}
DDRA = 0x00;/*获取列地址*/
PORTA = 0x0F;
DDRA = 0xF0;
delay_nms(20);//延时必须足够
k = PINA;
DDRA = 0x00;/*获取行地址*/
PORTA = 0xF0;
DDRA = 0x0F;
delay_nms(1);
k |= PINA;
DDRA = 0x00;/*输出复位*/
PORTA = 0xFF;
switch (k)
{/*将按键码转换成键值*/
case 0xEB: while((key_scan()) != 16);return 7;
case 0x77: while((key_scan()) != 16);return 13;
case 0x7B: while((key_scan()) != 16);return 12;
case 0x7D: while((key_scan()) != 16);return 11;
case 0xB7: while((key_scan()) != 16);return 14;
case 0xBB: while((key_scan()) != 16);return 9;
case 0xBD: while((key_scan()) != 16);return 6;
case 0xD7: while((key_scan()) != 16);return 0;
case 0xDB: while((key_scan()) != 16);return 8;
case 0xDD: while((key_scan()) != 16);return 5;
case 0x7E: while((key_scan()) != 16);return 10;
case 0xBE: while((key_scan()) != 16);return 3;
case 0xDE: while((key_scan()) != 16);return 2;
case 0xEE: while((key_scan()) != 16);return 1;
case 0xED: while((key_scan()) != 16);return 4;
case 0xE7: while((key_scan()) != 16);return 15;
default : return 16; //无键按下
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询