Mi informacion de contacto
Correo[email protected]
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Interrupción del temporizador (juicio) interrupción de la tecla del parámetro de tiempo (modificación)
DCD SysTick_Handler ; SysTick Handler
- void SysTick_Handler(void)
- {
-
- HAL_IncTick();//增加计数值,
-
- extern void check_timer(void);
- check_timer();
-
- }
- __weak void HAL_IncTick(void)
- {
- uwTick += uwTickFreq;
- }
-
- __weak uint32_t HAL_GetTick(void)
- {
- return uwTick;
- }
Hora de la manecilla y hora del reloj
Estructura del temporizadorFunción que contiene valores de conteo de tiempo y proceso.
en el sistemafunción de manejo del relojAgregue una función de verificación de reloj y la declaración if en check_timer limitará el tiempo del puntero para que sea menor o igual que el tiempo del reloj.
Si lo interrumpen, paseFunción de devolución de llamada de interrupciónAgregue 10 ms al tiempo de su propio puntero,Si ocurre otra interrupción durante este período, el tiempo del puntero se incrementará en 10.
Cuando no se produce ninguna interrupción o la interrupción se produce dentro de (n * 10) ms, no se cumplen las condiciones para ingresar al cuerpo de la función if en check_timer;
Ingrese el cuerpo de la función if hasta que no haya fluctuación.Llame a funciones en la estructura a través de la función de temporizador y la función check_timer,hacervalor de conteoAumentar
- struct soft_timer {
- uint32_t timeout;
- void * args;
- void (*func)(void *);
- };
-
- int g_key_cnt = 0;
-
- void key_timeout_func(void *args);
- struct soft_timer key_timer = {~0, NULL, key_timeout_func};
- void key_timeout_func(void *args)
- {
- g_key_cnt++;
- key_timer.timeout = ~0;
- }
-
- void mod_timer(struct soft_timer *pTimer, uint32_t timeout)
- {
- pTimer->timeout = HAL_GetTick() + timeout;
- }
-
- void check_timer(void)
- {
- if (key_timer.timeout <= HAL_GetTick())
- {
- key_timer.func(key_timer.args);
- }
- }
-
- 、、数据处理的源头,发生中断
- void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
- {
- if (GPIO_Pin == GPIO_PIN_14)
- {
- mod_timer(&key_timer, 10);
- }
- }
- int main(){
- OLED_Init();
- OLED_Clear();
- OLED_PrintString(0, 4, "Key ISR cnt = ");
- while (1)
- {
- OLED_PrintSignedVal(0, 6, g_key_cnt);
-
- }
-
- }
Manejador DCD EXTI15_10_IRQ; Línea EXTI 15..10
- void EXTI15_10_IRQHandler(void)
- {
- /* USER CODE BEGIN EXTI15_10_IRQn 0 */
-
- /* USER CODE END EXTI15_10_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
- /* USER CODE BEGIN EXTI15_10_IRQn 1 */
-
- /* USER CODE END EXTI15_10_IRQn 1 */
- }
Fuente de procesamiento de datos, se produce una interrupción.
- void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
- {
- /* EXTI line interrupt detected */
- if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
- {
- __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
- HAL_GPIO_EXTI_Callback(GPIO_Pin);
- }
- }