当前位置:网站首页>STM32 key development foundation

STM32 key development foundation

2022-06-26 01:17:00 m0_ forty-six million three hundred and twenty-one thousand one

The basic principle of key scanning

Key signal recognition :
Generally speaking, one end of the two pins of the key is pulled up to the high level through a resistor , The other end is grounded

When no key is pressed , The input pin is high , On the contrary, it is low level . By repeatedly reading the interval of this signal to determine whether there is a key trigger

To shake :

Influence of external noise , It may cause inaccurate reading level , At this time, it is necessary to shake , Remove the interference signal , So as to obtain the real key trigger signal

HAL Library level input function

Key signal recognition :HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uin16_t GPIO_Pin);

Identify level input , Enumerated 0 and 1 Two states

Example : Judge PC13 Input signal of pin , If high , Will PB9 Pin controlled LED The switch state of the lamp is switched

if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==GPIO_PIN_SET

#  The high level is GPIO_PIN_SET, The low level is GPIO_PIN_RESET

{

    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);

}

 

To configure STM32CubeMX and keil5

The previous ones are similar , Set up , Input pin and output pin , Now you are configuring separate pins , choice PC13 Mouth and PB1 Two , Select pull up , It is convenient to identify these pins in the program .

Here, the above configuration codes are basically the same

Defines a read function , When the switch is pressed , Switch LED The state of , The second is to press and release before switching .

modify GPIO Definition of mouth , find gpio.c The file finds this structure , Observe the pins , You can modify it directly .

 

原网站

版权声明
本文为[m0_ forty-six million three hundred and twenty-one thousand one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180558176188.html