/*按键扫描函数*/
#define key_port P1
unsigned char Keyscan(void){
unsigned char temp;
temp = key_port;
temp &=0xf0;
if(temp != 0xf0){ //检测按键是否被按下
delay_ms(5);
temp = key_port;
temp &= 0xf0;
if(temp != 0xf0){ //再次确认按键是否被按下
switch(temp){
case 0xe0:
return '1';
break;
case 0xd0:
return '2';
break;
case 0xb0:
return '3';
break;
case 0x70:
return '4';
break;
default:
break;
}
}
}
}
有四个按键,使用的是P1口高四位, |