#ifndef __KEY_H__ #define __KEY_H__ #include "delay.h"
uchar keys_scan() { delay(10); uchar keyno=16; P1DIR=0Xf0;//高四位输出,低四位输入 P1OUT=0xef; switch(P1IN&0x0f) { case 0x0e: keyno=4; break; case 0x0d: keyno=3; break; case 0x0b: keyno=2; break; case 0x07: keyno=1; break; } P1OUT=0xDf; switch(P1IN&0x0f) { case 0x0e: keyno=8; break; case 0x0d: keyno=7; break; case 0x0b: keyno=6; break; case 0x07: keyno=5; break; } P1OUT=0xBf; switch(P1IN&0x0f) { case 0x0e: keyno=12; break; case 0x0d: keyno=11; break; case 0x0b: keyno=10; break; case 0x07: keyno=9; break; } P1OUT=0x7f; switch(P1IN&0x0f) { case 0x0e: keyno=16; break; case 0x0d: keyno=15; break; case 0x0b: keyno=14; break; case 0x07: keyno=13; break; } delay(20); return keyno; } #endif
|