void keyscan()
{
uchar temp,z,x;
TRISB=0x0f;
PORTB=0x0f;
x=PORTB&0x0f;
if(x!=0x0f)
{
delay1ms(10);
x=PORTB&0x0f;
if(x!=0x0f)
{
temp=PORTB&0x0f;
TRISB=0xf0;
PORTB=0xf0;
z=temp|PORTB;
x=PORTB&0xf0;
while(x!=0xf0)//松手检测
{
x=PORTB&0xf0;
}
switch(z)
{
case0xee: num =0; break;
case 0xde: num =4; break;
case 0xbe: num =8; break;
case 0x7e: num =12; break;
case 0xed: num =1; break;
case 0xdd: num =5; break;
case 0xbd: num =9; break;
case 0x7d: num =13; break;
case 0xeb: num =2; break;
case 0xdb: num =6;break;
case 0xbb: num =10;break;
case 0x7b: num =14;break;
case 0xe7: num =3;break;
case 0xd7: num =7;break;
case 0xb7: num =11;break;
case 0x77: num =15;break;
}
}
}
}