|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?快速注册
×
#include<reg52.h>
#define TRUE 1
#define FALSE 0
#define LEDPort P0
#define keyPort P1
#define uchar unsigned char
#define uint unsigned int
#define keyTemp 0xf0
uint i;
uchar j;
uint temp;
uint keyNum;
uchar keyCnt;
const uchar code LEDMap[] ={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x7e,0x7d,0x7b,0x77};
const uchar code keyMap[] ={0xf6,0xf5,0xf3};
void delay(uint delayTime){
for(i=0;i<delayTime;i++)
for(j=0;j<110;j++);
}
void init(){
TMOD=0x0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
keyNum=-1;
}
void drawKey(uchar thumbs){
LEDPort=LEDMap[thumbs-1];
}
uchar keyScan(){
for(keyCnt=0;keyCnt<3;keyCnt++){
keyPort=keyMap[keyCnt];
temp=keyPort;
temp=temp&keyTemp;
if(temp!=keyTemp){
delay(10);
temp=keyPort;
temp=temp&keyTemp;
if(temp!=keyTemp){
switch(temp){
case 0xe0:keyNum=keyCnt+1; drawKey(keyNum);break;
case 0xd0:keyNum=keyCnt+4; drawKey(keyNum);break;
case 0xb0:keyNum=keyCnt+7; drawKey(keyNum);break;
case 0x70:keyNum=keyCnt+10;drawKey(keyNum);break;
}
while(temp!=keyTemp){
temp=keyPort;
temp=temp&0xf0;
}
}
}
}
return keyNum;
}
void main(){
init();
while(TRUE){
keyScan();
}
}
哈,应该没有难点
|
评分
-
1
查看全部评分
-
|