uchar Keyboard_Scan(void)
{
uchar scancode,tmpcode;
P2=0xf0;
while(P2==0xf0); //等待有键按下
Delay_1ms(20); //延时10ms去抖动
if(P2!=0xf0)
{ scancode=0xfe; //逐行扫描
while(scancode!=0xef) //还没有扫描完4行
{
P2=scancode;
if((P2&0xf0)!=0xf0) //本列有键按下
{
tmpcode=(P2&0xf0)|(scancode&0x0f);
while((P2&0xf0)!=0xf0); //等待键释放
return(tmpcode);
}
else scancode=(scancode<<1)|0x01;
}
}
return(0);
}
此帖出自
小平头技术问答
一周热门 更多>