(2) Embedded Blue Bridge Cup-Button

(1) Personal habits

Will create separate KEY.c and KEY.h and put them under the HARAWARE folder

(2) Write void KEY_init (void) function

Note; this IO is configured as a pull-up input
Insert picture description here

(3) Write a macro to define the button status bit

Insert picture description here

(4) Write void KEY_read (void) function

Insert picture description here

(5) Problem

Question one (1) (2):
According to its hardware connection:
Insert picture description here

Question two:
(1) It can achieve the effect of anti-shake, and also serve as a time reference for the long press/short press later
(2) It can be seen in the SysTick timer
Insert picture description here

Question three:
In order to facilitate reading the level status of the button IO port

(6) Long press / short press

(1) When key_temp=1, it means a short press
(2) If it is key_temp=10, the pressing time must exceed 10*50ms=500ms to take effect

Guess you like

Origin blog.csdn.net/m0_46278925/article/details/113088376