cortex-m0用外设4*4的键盘接入后按下键在cortex-m0的显示器显示
时间:10-02
整理:3721RD
点击:
用外设4*4的键盘接入后按下键在cortex-m0的显示器显示相应按键信息
按键信息如下
**********
1 2 3 A
4 5 6 B
7 8 9 C
* 0 # D
*********
最好有代码,谢谢了,有急用!
3*3的键盘操作方式 参考一下吧
- #include <lpc17xx.h>
- #include "key.h"
- #define KEY_ROW1_PIN 25
- #define KEY_ROW2_PIN 24
- #define KEY_ROW3_PIN 23
- #define KEY_COL1_PIN 20
- #define KEY_COL2_PIN 21
- #define KEY_COL3_PIN 22
- uint32_t key_count = 0;
- KEY_STATE key_state = KEY_NULL;
- KEY_STATE key_state_new = KEY_NULL;
- KEY_STATE key_state_old = KEY_NULL;
- /*----------------------------------------------------------------------------
- read key Pins
- *----------------------------------------------------------------------------*/
- KEY_STATE readkey(void)
- {
- uint8_t KEY_H = 0, KEY_L = 0;
- uint32_t key;
- uint32_t i=0;
-
- LPC_GPIO0->FIODIR &= ~((1<<20)|(1<<21)|(1<<22));
- LPC_GPIO0->FIODIR |= (1<<KEY_ROW1_PIN)|(1<<KEY_ROW2_PIN)|(1<<KEY_ROW3_PIN);
- LPC_GPIO0->FIOCLR |= (1<<KEY_ROW1_PIN)|(1<<KEY_ROW2_PIN)|(1<<KEY_ROW3_PIN);
- for(i=0;i<200;i++);
- key = LPC_GPIO0->FIOPIN & ((1<<20)|(1<<21)|(1<<22));
- key = key >> 20;
- if( key < 7 )
- {
- switch(key){
- case 3:
- KEY_H = 0;
- break;
- case 5:
- KEY_H = 1;
- break;
- case 6:
- KEY_H = 2;
- break;
- default:
- KEY_H = 0;
- break;
- }
-
-
- LPC_GPIO0->FIODIR &= ~((1<<KEY_ROW1_PIN)|(1<<KEY_ROW2_PIN)|(1<<KEY_ROW3_PIN));
- LPC_GPIO0->FIODIR |= (1<<20)|(1<<21)|(1<<22);
- LPC_GPIO0->FIOCLR |= (1<<20)|(1<<21)|(1<<22);
-
- for(i=0;i<200;i++);
-
- key = LPC_GPIO0->FIOPIN &((1<<KEY_ROW1_PIN)|(1<<KEY_ROW2_PIN)|(1<<KEY_ROW3_PIN));
- key = key >> KEY_ROW3_PIN;
- if( key < 7 )
- {
- switch(key){
- case 3:
- KEY_L = 1;
- break;
- case 5:
- KEY_L = 4;
- break;
- case 6:
- KEY_L = 7;
- break;
- default:
- KEY_L = 0;
- KEY_H = 0;
- break;
- }
- }
-
- key_state_new = (KEY_STATE)(KEY_H+KEY_L);
-
- if( key_state_old != key_state_new)
- {
- key_count++;
- if( key_count >= 10)
- {
- key_count = 0;
- key_state_old = key_state_new;
- key_state = key_state_new;
- }
- }
- }
- else
- {
- key_state_old = KEY_NULL;
- }
-
- return key_state;
- }
- void setkey(KEY_STATE state)
- {
- key_state = state;
- }
相当于你给每一个按键都分配了一个功能,就是按键检查和串口显示问题,自己多多查查资料,可以解决的。扫描按键现在示例多得很。
十分感谢了!我记下了谢谢您!