|
首先检查按键是否按下,然后对按键进行扫描。
uchar checkkey(void)
{ uchar temp;
P1=0xf0;
temp=P1;
temp=temp&0xf0;
if(temp==0xf0)
{ delay1();
if(temp==0xf0)
{return(0);
}else{return(1);}
}
}
uchar keyscan()
{ uchar hanghao,liehao,keyvalue,buff;
if(checkkey()==0)
{ return(10);
}
else
{uchar sound;
for(sound=50;sound>0;sound--)
{speaker=0;
delay1();
speaker=1;
delay1();
}
P1=0x0f;
buff=P1;
if(buff==0x0e)
{hanghao=1;}
else if(buff==0x0d)
{hanghao=5;}
else if(buff==0x0b)
{hanghao=9;}
else if(buff==0x07)
{hanghao=13;}
P1=0xf0;
buff=P1;
if(buff==0xe0)
{liehao=3;}
else if(buff==0xd0)
{liehao=2;}
else if(buff==0xb0)
{liehao=1;}
else if(buff==0x70)
{liehao=0;}
keyvalue=hanghao+liehao;
while(P1!=0xf0);
return(keyvalue);} |
|