STM32F4实现矩阵键盘
来源:互联网 发布:电气控制柜设计软件 编辑:程序博客网 时间:2024/06/03 15:36
程序中所使用的矩阵键盘所接的引脚为PC4-PC5、PF11-PF15和PG0,接线方法为常规矩阵键盘的接法,PC4、PC5、PF11、PF12为行线PF13、PF14、PF15、PG0为列线。
u8 check_Key(void){ GPIO_InitTypeDef GPIO_InitStructure; u8 cord_h=0XFF,cord_l=0XFF; //h为行线 l为列线 u8 Val = 0xFF; /* 行线 推挽输出 */ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_12; GPIO_Init(GPIOF,&GPIO_InitStructure); /* 列线 上拉输入 */ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; GPIO_Init(GPIOG,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_Init(GPIOF,&GPIO_InitStructure); /* 行线输出全部设置为0 */ GPIO_WriteBit(GPIOC, GPIO_Pin_4|GPIO_Pin_5, Bit_RESET); GPIO_WriteBit(GPIOF, GPIO_Pin_11|GPIO_Pin_12, Bit_RESET); delay_us(1); /* 读入列线值 读入的值分别存入低四位 高四位全部为0 */ cord_l&=(u8)((GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_13)<<0)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_14)<<1)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_15)<<2)| (GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_0)<<3)); if(cord_l!=0X0F) { delay_ms(10); //消抖 延时后再读一次 cord_l&=(u8)((GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_13)<<0)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_14)<<1)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_15)<<2)| (GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_0)<<3)); if(cord_l!=0X0F) { /* 交换输入信号读取行线值 */ /* 列线 推挽输出 */ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; GPIO_Init(GPIOG,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_Init(GPIOF,&GPIO_InitStructure); /* 行线 上拉输入 */ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_12; GPIO_Init(GPIOF,&GPIO_InitStructure); /* 列线输出全部设置为0 */ GPIO_WriteBit(GPIOG, GPIO_Pin_0, Bit_RESET); GPIO_WriteBit(GPIOF, GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15, Bit_RESET); delay_ms(2); /* 读入行线值 */ cord_h&=(u8)((GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4)<<3)| (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5)<<2)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_11)<<1)| (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_12)<<0)); Val=~(cord_h<<4|cord_l); //取反 便于分析Val对应的按键 return Val; } } return ~Val;}
阅读全文
1 0
- STM32F4实现矩阵键盘
- VHDL实现矩阵键盘检测
- 单片机矩阵键盘的实现
- STM32F407实现矩阵键盘程序
- 4*4矩阵键盘的实现方式
- 计算器 1602 和 矩阵键盘栈实现
- 矩阵键盘线反转法实现
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- 矩阵键盘
- FFMPEG添加新的Filter
- 自定义 TextView 两端对齐
- JAVAEE 从一个Android到用javaee开发第一个接口
- @Override注解报错,The method xxx of type xxx must override a superclass method
- 84坐标系、02坐标系、百度坐标之间相互转换算法
- STM32F4实现矩阵键盘
- 如何分析java中<? extends Comparable<? super T>>
- 纪念一下,2017年9月11日粗略看完了廖大的python教程
- Java多线程--final与多线程
- 压缩流
- 汇付天下债权转让接口格式
- 数据结构与算法(6)---Java语言实现:冒泡排序
- npm 安装browser-sync 实时监听本地网页文件的变化
- thinkphp多表操作事务回滚