From f1bc6bd8e129820a05e9a398f8979b5238634d94 Mon Sep 17 00:00:00 2001 From: 423A35C7 <609514299@qq.com> Date: Tue, 29 Oct 2024 21:20:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=AC=AC=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exp2/Core/Inc/variable.h | 2 ++ exp2/Core/Src/main.c | 4 +++- exp2/Core/Src/stm32g4xx_it.c | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/exp2/Core/Inc/variable.h b/exp2/Core/Inc/variable.h index ca1c8fb..55d385e 100644 --- a/exp2/Core/Inc/variable.h +++ b/exp2/Core/Inc/variable.h @@ -9,6 +9,8 @@ extern "C" { typedef struct { uint8_t mMilSecCount; // 毫秒计数 uint8_t bTenMilSecOk; // 10毫秒标志位 + uint8_t mTenMilSecCount; // 10毫秒计数 + uint8_t bHundredMilSecOk; // 100毫秒标志位 uint8_t mTimeCount; // 秒计数 uint8_t bTimeOk; // 秒标志位 } stSysTickTimer; diff --git a/exp2/Core/Src/main.c b/exp2/Core/Src/main.c index 1cf3dbf..a5c334b 100644 --- a/exp2/Core/Src/main.c +++ b/exp2/Core/Src/main.c @@ -104,7 +104,9 @@ int main(void) if (sSysTickTimer.bTimeOk) { sSysTickTimer.bTimeOk = 0; HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); - + } + if (sSysTickTimer.bHundredMilSecOk) { + sSysTickTimer.bHundredMilSecOk = 0; HAL_GPIO_WritePin(FlashLeds_GPIO_Port, nShift, GPIO_PIN_SET); diff --git a/exp2/Core/Src/stm32g4xx_it.c b/exp2/Core/Src/stm32g4xx_it.c index 0be82fa..76a8846 100644 --- a/exp2/Core/Src/stm32g4xx_it.c +++ b/exp2/Core/Src/stm32g4xx_it.c @@ -192,9 +192,13 @@ void SysTick_Handler(void) if (++sSysTickTimer.mMilSecCount >= 10) { sSysTickTimer.mMilSecCount = 0; sSysTickTimer.bTenMilSecOk = 1; - if (++sSysTickTimer.mTimeCount >= 100) { - sSysTickTimer.mTimeCount = 0; - sSysTickTimer.bTimeOk = 1; + if (++sSysTickTimer.mTenMilSecCount >= 10) { + sSysTickTimer.mTenMilSecCount = 0; + sSysTickTimer.bHundredMilSecOk = 1; + if (++sSysTickTimer.mTimeCount >= 10) { + sSysTickTimer.mTimeCount = 0; + sSysTickTimer.bTimeOk = 1; + } } } /* USER CODE END SysTick_IRQn 1 */