今天在网上看到一种矩阵键盘的线反转法程序,感觉挺好,比之前的扫描法节省了很多,在此分享一下uchar key(void)
{
uchar key,key1,key2,k;
P1=0XF0;
k=0xff;
if((P1&0XF0)!=0XF0)
{
delay();
if((P1&0XF0)!=0XF0)
key1=P1&0XF0;
P1=0X0F;
if((P1&0X0F)!=0X0F)
{
delay();
if((P1&0X0F)!=0X0F)
{
key2=P1&0X0F;
key=key1|key2;
if(key!=0xff)
{
switch(key)
{
case 0xee: k=0;break;
case 0xed: k=1;break;
case 0xeb: k=2;break;
case 0xe7: k=3; break;
case 0xde: k=4;break;
case 0xdd: k=5;break;
case 0xdb: k=6;break;
case 0xd7: k=7; break;
case 0xbe: k=8;break;
case 0xbd: k=9;break;
case 0xbb: k=10;break;
case 0xb7: k=11; break;
case 0x7e: k=12;break;
case 0x7d: k=13;break;
case 0x7b: k=14;break;
case 0x77: k=15; break;
}
}
}
}
}
return(k);
}