当前位置:   article > 正文

stm32 薄膜键盘原理_stm32F4----薄膜4*4矩阵键盘读取(七)

按键行为输出列为输入

买了个矩阵键盘,原理图如下:

左边的为行,右边的为列,扫描的原理大概如下:行为输出,列为输入。先让第一行为0,其他行为高,读取列的电平。

key.c如下:#include "key.h"

#include "delay.h"

//键值表

/*

1:0x01    2:0x02    3:0x03    A:0x04

4:0x05    5:0x06    6:0x07    B:0x08

7:0x09    8:0x0A    9:0x0B    C:0x0C

*:0x0D    0:0x0E    #:0x0F    D:0x10

*/

uint8_t keyNum = 0x00;   //键值

void  keyInit(void)

{

GPIO_InitTypeDef   GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);

//key row1  output

GPIO_InitStructure.GPIO_Pin  =  KEY_ROW1_PIN;

GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_Speed=  GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_OType=  GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd =  GPIO_PuPd_UP;

GPIO_Init(KEY_ROW1_PORT,&GPIO_InitStructure);

//key row2  output

GPIO_InitStructure.GPIO_Pin  =  KEY_ROW2_PIN;

GPIO_Init(KEY_ROW2_PORT,&GPIO_InitStructure);

//key row3  output

GPIO_InitStructure.GPIO_Pin  =  KEY_ROW3_PIN;

GPIO_Init(KEY_ROW3_PORT,&GPIO_InitStructure);

//key row4  output

GPIO_InitStructure.GPIO_Pin  =  KEY_ROW4_PIN;

GPIO_Init(KEY_ROW4_PORT,&GPIO_InitStructure);

//key col1  input

GPIO_InitStructure.GPIO_Pin  =  KEY_COL1_PIN;

GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_IN;

GPIO_InitStructure.GPIO_Speed=  GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd =  GPIO_PuPd_UP;

GPIO_Init(KEY_COL1_PORT,&GPIO_InitStructure);

//key col2  input

GPIO_InitStructure.GPIO_Pin  =  KEY_COL2_PIN;

GPIO_Init(KEY_COL2_PORT,&GPIO_InitStructure);

//key col3  input

GPIO_InitStructure.GPIO_Pin  =  KEY_COL3_PIN;

GPIO_Init(KEY_COL3_PORT,&GPIO_InitStructure);

//key col4  input

GPIO_InitStructure.GPIO_Pin  =  KEY_COL4_P

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/302191
推荐阅读
相关标签
  

闽ICP备14008679号