char kbscan() //键盘扫描
{
unsigned char hang,lie,key;
if(P3!=0x0f)
{
delay(5);
if(P3!=0x0f)
{
switch(P3&0x0f)
{
case 0x0e:lie=0;break;
case 0x0d:lie=1;break;
case 0x0b:lie=2;break;
case 0x07:lie=3;break;
}
P3=0xf0;
switch(P3&0xf0)
{
case 0xe0:hang=0;break;
case 0xd0:hang=1;break;
case 0xb0:hang=2;break;
case 0x70:hang=3;break;
}
P3=0x0f;//重要,必须归位
while(P3!=0x0f);//
key=tab[hang][lie];
}
}
else
key=0;
return (key);
}
05-12