单片机键盘扫描实验
代码如下:
//实例7
#include
//led字模
char led_mod[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
//键值
char key_buf[] = {0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,
char getKey(void);
void delay(unsigned int time){
unsigned int j = 0;
for(;time>0;time--)
}
void main(void) {
char key = 0;
P2 = 0x00;
//P0=0x11;
while(1) {
if (key != -1) {
P2 = led_mod[key];
}
delay(10);
}
}
//检测按键
//返回-1表示没有检测到按键按下
char getKey(void) {
char i = 0;
unsigned char keycode=0xff;
unsigned char scancode=0xff;
scancode=0xf7;
P0=0xf0;
while(scancode!=0xff) {
P0=scancode;
//delay(10);
keycode=P0;
if((keycode&0xf0)!=0xf0)break;
scancode=(keycode>>1)|0xf0;
//if(keycode==0xff)scancode=scancode&0xf0;
}
keycode=~keycode;
for (i = 0 ; i < 16 ; i++) {
return-1;
}
单片机键盘扫 相关文章:
- 51单片机之键盘扫描方式程序讲解(11-28)
- 单片机键盘扫描程序(4*4)(11-26)
- At89c51单片机键盘扫描和显示程序(11-22)
- 单片机键盘扫描程序(汇编)(11-18)
- 单片机键盘扫描方法两种(11-18)
- Windows CE 进程、线程和内存管理(11-09)