当前位置:网站首页>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;
边栏推荐
- If you want to grow rapidly, you must first experience a major blow!
- Idea generate class diagram plug-in UML (super detailed)
- [binary tree] pseudo palindrome path in binary tree
- 2022年一级建造师考试什么时候才能报名?
- 771. 字符串中最长的连续出现的字符
- imx6q gpio复用
- 75. Color classification (medium array double pointer sorting)
- 示波器发展史中的变化
- [LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
- 使用PCL批量将点云.bin文件转.pcd
猜你喜欢

Establishment of Ruiji takeout development environment

Summary of common error types in JS

Baidu map usage

Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method

Qt+FFmpeg环境搭建

JMeter installs third-party plug-ins plugins Manager
![[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login](/img/53/c578e0d1428ea569fb412a20019924.png)
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
![[virtual machine _2]-hyper-v and vmware/virtualbox cannot coexist](/img/90/c481a817dc91d7e5247dd8e3ee1dae.png)
[virtual machine _2]-hyper-v and vmware/virtualbox cannot coexist

Imx6q GPIO multiplexing

PaddleNLP基于ERNIR3.0文本分类:WOS数据集为例(层次分类)
随机推荐
How to realize dynamic route switching and route caching in vuejs
MySQL installation and configuration (super detailed, simple and practical)
Imx6q GPIO multiplexing
Excel-VBA 快速上手(十三、日期的常见用法)
AWK空行过滤
Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line
Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)
Sword finger offer II 065. The shortest word code (medium dictionary tree string array)
gprs网络指的是什么
MOV格式是不是静态图像文件格式
Soft exam network engineer
For loops and functions
Static route and default route experiment
ssh免密登陆
98. Verify binary search tree (medium binary search tree DFS)
Log4j vulnerability elk platform processing method (logstah5.5.1)
If you want to grow rapidly, you must first experience a major blow!
The blueprint of flask complements openpyxl
Ruiji takeout project - development of business development function Day2
ATT&CK初步了解