以下是一个4乘4的键盘扫描程序,好像没有延时去抖动什么的,不知道有没有问题,麻烦各位高手帮帮忙看一下有没有问题? 还需不需要加什么?
void Tkey(void) { uchar readkey; uchar x_temp,y_temp; P1=0x0f; x_temp=P1&0x0f; if(x_temp==0x0f) goto keyout; P1=0xf0; y_temp=P1&0xf0; readkey=x_temp|y_temp; readkey=~readkey;
switch(readkey) { case 0x11:key=0; break; case 0x21:key=1; break; case 0x41:key=2; break; case 0x81:key=3; break; case 0x12:key=4; break; case 0x22:key=5; break; case 0x42:key=6; break; case 0x82:key=7; break; case 0x14:key=8; break; case 0x24:key=9; break; case 0x44:key=10;break; case 0x84:key=11;break; case 0x18:key=12;break; case 0x28:key=13;break; case 0x48:key=14;break; case 0x88:key=15;break; default: key=16;break; }
keyout:_nop_(); }
|