请问大家,怎样在不增加按键的情况下,如何从矩阵键盘中分离出3个按键使用,并要求使用3个按键时,其它按键无效,
程序如下,怎样修改呢?
unsigned char getkey(void)
{
unsigned char rcode,ccode;
while (key_scan())
delay(1);
P1=0x0f;
rcode=P1&0x0f;
if(rcode!=0x0f)
{
delay(1);
i f(rcode!=0x0f)
{
rcode=P1&0x0f;
P1=rcode|0xf0;
ccode=P1&0xf0;
return(rcode+ccode);
}
}
return(0xff);
}
unsigned char keyscan(void)
{
getkey();
switch(keybord)
{
case 0xee:keynum=1;K1=1;break;//要使用k1、k2、k3
case 0xed:keynum=2;K2=1;break;//
case 0xeb:keynum=3;K3=1;break;//
case 0xe7:keynum=11;break;
case 0xde:keynum=4;break;
case 0xdd:keynum=5;break;
case 0xdb:keynum=6;break;
case 0xd7:keynum=13;break;
case 0xbe:keynum=7;break;
case 0xbd:keynum=8;break;
case 0xbb:keynum=9;break;
case 0xb7:keynum=14;break;
case 0x7e:keynum=10;break;
case 0x7d:keynum=0;break;
case 0x7b:keynum=12;break;
case 0x77:keynum=15;break;
default:break;
}
while (~key_scan())
delay(1);
return 0;
}
void main()
{
lcd_rest() ;
dis_inputpsw();
keyscan();
while(1)
{
while (keynum>=1 && keynum<=3) //非1-3的数字则不响应
keyscan();
if(K1)
{
dis_pswwrong(); //显示
}
if(K2)
{
dis_changepsw();
}
if(K3)
{
dis_newpsw();
}
}
} |