当前位置:网站首页>STM32 board level support package for keys
STM32 board level support package for keys
2022-07-28 22:37:00 【Green hedgerow bamboo maple】

Board support package for keys , initialization GPIO( Input configured as , Read GPIO Pin level )
Read whether the key is pressed , That is, the state of the key
Key use PA0 and PC13 Pin
First create bsp_key.c and bsp_key.h file

hold bsp_key.c Add to the project

bsp_key.h Writing process
Define the executable functions in this file , Pin status
#ifndef _BSP_KEY_H_
#define _BSP_KEY_H_
// Import this header file , Ability to visit HAL function library
#include "stm32f1xx.h"
// The macro definition represents the key state
#define KEY_ON 1;
#define KEY_OFF 0;
// initialization KEY Corresponding GPIO Pin
void KEY_GPIO_Init(void);
// Determine the status of the key , Customize 2 Parameter types , Which pin , And pin number , There is a return value , Easy to judge the state
uint8_t Key_Scan(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin);
#endifbsp_key.c Writing process
#include "./key/bsp_key.h"
void KEY_GPIO_Init(void)
{
GPIO_InitTypeDef KEY_GPIO_Init;
// Because it's used PA0 and PC13 foot , To enable these two ports
// Can make PA0 Pin
__HAL_RCC_GPIOA_CLK_ENABLE();
// Can make PC13 Pin
__HAL_RCC_GPIOC_CLK_ENABLE();
//stm32f1xx_hal_gpio.h The first 116 That's ok
//#define GPIO_MODE_INPUT 0x00000000u /*!< Input Floating Mode */
// Set pin function
KEY_GPIO_Init.Mode=GPIO_MODE_INPUT;
KEY_GPIO_Init.Pin=GPIO_PIN_0;
KEY_GPIO_Init.Pull=GPIO_NOPULL;
KEY_GPIO_Init.Speed=GPIO_SPEED_FREQ_LOW;
// initialization 2 individual GPIO Pin
HAL_GPIO_Init(GPIOA,&KEY_GPIO_Init);
KEY_GPIO_Init.Pin=GPIO_PIN_13;
HAL_GPIO_Init(GPIOC,&KEY_GPIO_Init);
}
// Write a function to judge whether the key is pressed
uint8_t Key_Scan(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
// Judge whether the key is pressed , Find this method to know ,GPIO_PIN_SET High level
if(HAL_GPIO_ReadPin(GPIOx,GPIO_Pin)==GPIO_PIN_SET){
// Key pressed
while(HAL_GPIO_ReadPin(GPIOx,GPIO_Pin)==GPIO_PIN_SET);
return KEY_ON;
}else{
// Key not pressed
return KEY_OFF;
}
}stay main.c To complete the required functions

if(Key_Scan(GPIOA,GPIO_PIN_0)== KEY_ON)
LED_B_Toggle;
if(Key_Scan(GPIOC,GPIO_PIN_13)==KEY_ON)
LED_G_Toggle;
边栏推荐
- NPM switch Taobao source (NPM source)
- Overall introduction of Ruiji takeout project
- 普源示波器实际的使用效果怎么样
- [leetcode] maximum depth of binary tree
- There will be a black line on the border when the button in the wechat applet is clicked
- 775. 倒排单词
- What is time complexity
- PaddleNLP基于ERNIR3.0文本分类以中医疗搜索检索词意图分类(KUAKE-QIC)为例【多分类(单标签)】
- For loops and functions
- mysql create语句能不能用来建立表结构并追加新的记录
猜你喜欢
How do we do full link grayscale on the database?

79. Word search (medium string array matrix backtracking)
![[CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation](/img/3d/3def78ec88419712e14cf437e21447.png)
[CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation

【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络

使用PCL批量显示PCD点云数据流

Lvs+keepalived high availability deployment practical application

SQL injection less42 (post stack injection)

6K6w5LiA5qyh5pS75Ye75YiG5p6Q

npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...

Ultra detailed visual studio 2019 running littlevgl (lvgl) simulator
随机推荐
There will be a black line on the border when the button in the wechat applet is clicked
79. Word search (medium string array matrix backtracking)
MySQL built-in functions
Common commands of NPM
776. 字符串移位包含问题
98. Verify binary search tree (medium binary search tree DFS)
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
想要快速成长,先要经历重大打击!
Sword finger offer II 066. sum of words (medium prefix tree design string)
[CS231N]Lecture_ 2:Image Classification pipelin
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
Why doesn't the icon on the elment plus icon input display
纪念一下第一次写的线段树了喽(对应洛谷3372)
For loops and functions
LCR测试仪最为主要的功能和用途都是什么
Ecmasript 5/6 notes
How to realize dynamic route switching and route caching in vuejs
使用PCL批量显示PCD点云数据流
Ngrok intranet penetration
Win11怎么打开软件通知