基于STM32L151//STM32F407的矩阵键盘程序(不规则接口):
来源:互联网 发布:淘宝开店品牌怎么填 编辑:程序博客网 时间:2024/06/05 02:06
最近在做一个有关按键的项目,需要用到矩阵键盘,上网找了很多都是基于一些规则接口的程序,感觉无语,因为画PCB由于布线原因
不太可能矩阵键盘的几条线是连接连续的GPIO口,所以经过我自己思考,做出了自己基于STM32的不规则程序,
由于每种矩阵键盘的连接原理有时是不同,所以首先先讲明我的矩阵键盘的连接原理
4条行线初始化时全为1,列线全为0,由于我的列先有接10K的电阻,有按键按下时,被按下的列线为1,
行线一次置为1、0、0、0\\0,1,0,0\0,0,1,0\0,0,0,1
不太可能矩阵键盘的几条线是连接连续的GPIO口,所以经过我自己思考,做出了自己基于STM32的不规则程序,
由于每种矩阵键盘的连接原理有时是不同,所以首先先讲明我的矩阵键盘的连接原理
4条行线初始化时全为1,列线全为0,由于我的列先有接10K的电阻,有按键按下时,被按下的列线为1,
行线一次置为1、0、0、0\\0,1,0,0\0,0,1,0\0,0,0,1
基于STM32L151//STM32F407的矩阵键盘程序(不规则接口):
行接口:PA8,PA12,PB3,PB4
列接口:PA11,PB5,PB9
列接口:PA11,PB5,PB9
void KeyPress(void){
int KeyValues;
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1)
{
Delay10ms(20);
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_9);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
GPIO_SetBits(GPIOA,GPIO_Pin_8);
GPIO_ResetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4);
GPIO_ResetBits(GPIOA,GPIO_Pin_12);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)==1)
{
KeyValues=10;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)==1)
{
KeyValues=11;
}
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1);
/////////////////////////////////////////////
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_9);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
GPIO_SetBits(GPIOA,GPIO_Pin_12);
GPIO_ResetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4);
GPIO_ResetBits(GPIOA,GPIO_Pin_8);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)==1)
{
KeyValues=7;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)==1)
{
KeyValues=8;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1)
{
KeyValues=9;
}
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1);
//////////////////////////////////////////////
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_9);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
GPIO_SetBits(GPIOB,GPIO_Pin_3);
GPIO_ResetBits(GPIOB,GPIO_Pin_4);
GPIO_ResetBits(GPIOA,GPIO_Pin_8|GPIO_Pin_12);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)==1)
{
KeyValues=4;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)==1)
{
KeyValues=5;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1)
{
KeyValues=6;
}
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1);
////////////////////////////////////////////////
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_9);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
GPIO_ResetBits(GPIOB,GPIO_Pin_3);
GPIO_SetBits(GPIOB,GPIO_Pin_4);
GPIO_ResetBits(GPIOA,GPIO_Pin_8|GPIO_Pin_12);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)==1)
{
KeyValues=1;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)==1)
{
KeyValues=2;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1)
{
KeyValues=3;
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_11)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)||GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1);
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_9);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
GPIO_SetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4);
GPIO_SetBits(GPIOA,GPIO_Pin_8|GPIO_Pin_12);
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
!!!!上图附有本程序的矩阵键盘原理,与普通矩阵键盘设计不太一样!!!!!!
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
0 0
- 基于STM32L151//STM32F407的矩阵键盘程序(不规则接口):
- STM32F407实现矩阵键盘程序
- 基于STM32F407的超声波测距程序
- 51 单片机 C 语言:不规则的矩阵键盘
- 基于stm32f103的矩阵键盘
- 基于51单片机矩阵键盘程序
- 基于stm32的遥控小船(四)矩阵键盘
- 矩阵键盘的扫描接口函数
- 基于C8051F410的矩阵键盘设计
- 矩阵键盘接口
- 基于stm32f407下的W5500网卡驱动(上)
- 基于stm32f407下的W5500网卡驱动(下)
- 基于FPGA的PS2接口键盘驱动
- STM32L151 usart2 串口2 程序
- 个人感觉很好的键盘矩阵键盘扫描程序
- 矩阵键盘扫描程序
- 矩阵键盘扫描程序
- 基于操作系统的键盘板显示程序(LPC2103版本)
- Linux基础入门
- 基础算法分治
- READING NOTE: A Pursuit of Temporal Accuracy in General Activity Detection
- vimrc备份
- Android基础之应用Service
- 基于STM32L151//STM32F407的矩阵键盘程序(不规则接口):
- Lodash中十个常用的工具函数
- 人工智能商业应用成功的六大必要条件
- HTML5-网页绘画板
- No4.Week 4
- leetcode 139. Word Break
- TextView属性大全及跑马灯效果
- SpringMVC源码-消息转换器HttpMessageConverter
- 设计模式---适配器模式(C++实现)