From b0ebd03d1999d6f59db07d9a17c1014013964b41 Mon Sep 17 00:00:00 2001 From: 423A35C7 <609514299@qq.com> Date: Tue, 8 Oct 2024 21:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=AE=9E=E9=AA=8C-?= =?UTF-8?q?=E4=B8=8A=E8=AF=BE=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exp1/Core/Inc/variable.h | 20 ++++++ exp1/Core/Src/main.c | 15 ++++- exp1/Core/Src/stm32g4xx_it.c | 12 +++- exp1/MDK-ARM/exp1.uvprojx | 123 +++++++++++++++++++---------------- 4 files changed, 109 insertions(+), 61 deletions(-) create mode 100644 exp1/Core/Inc/variable.h diff --git a/exp1/Core/Inc/variable.h b/exp1/Core/Inc/variable.h new file mode 100644 index 0000000..ca1c8fb --- /dev/null +++ b/exp1/Core/Inc/variable.h @@ -0,0 +1,20 @@ +#include +#ifndef __VARIABLE_H +#define __VARIABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint8_t mMilSecCount; // 毫秒计数 + uint8_t bTenMilSecOk; // 10毫秒标志位 + uint8_t mTimeCount; // 秒计数 + uint8_t bTimeOk; // 秒标志位 +} stSysTickTimer; + +#ifdef __cplusplus +} +#endif + +#endif /* __VARIABLE_H */ diff --git a/exp1/Core/Src/main.c b/exp1/Core/Src/main.c index 80e2a95..56a05b5 100644 --- a/exp1/Core/Src/main.c +++ b/exp1/Core/Src/main.c @@ -22,7 +22,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "variable.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -43,7 +43,9 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ - +stSysTickTimer sSysTickTimer = { + 0, 0, 0, 0 +}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -97,6 +99,15 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ + if (sSysTickTimer.bTenMilSecOk) { + sSysTickTimer.bTenMilSecOk = 0; + } + if (sSysTickTimer.bTimeOk) { + sSysTickTimer.bTimeOk = 0; + HAL_GPIO_TogglePin(TickClock_LED_GPIO_Port, TickClock_LED_Pin); + } + // HAL_GPIO_TogglePin(TickClock_LED_GPIO_Port, TickClock_LED_Pin); + // HAL_Delay(100); } /* USER CODE END 3 */ } diff --git a/exp1/Core/Src/stm32g4xx_it.c b/exp1/Core/Src/stm32g4xx_it.c index 4d03374..7aee366 100644 --- a/exp1/Core/Src/stm32g4xx_it.c +++ b/exp1/Core/Src/stm32g4xx_it.c @@ -22,6 +22,7 @@ #include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "variable.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -57,7 +58,7 @@ /* External variables --------------------------------------------------------*/ /* USER CODE BEGIN EV */ - +extern stSysTickTimer sSysTickTimer; /* USER CODE END EV */ /******************************************************************************/ @@ -187,7 +188,14 @@ void SysTick_Handler(void) /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ - + if (++sSysTickTimer.mMilSecCount >= 10) { + sSysTickTimer.mMilSecCount = 0; + sSysTickTimer.bTenMilSecOk = 1; + if (++sSysTickTimer.mTimeCount >= 100) { + sSysTickTimer.mTimeCount = 0; + sSysTickTimer.bTimeOk = 1; + } + } /* USER CODE END SysTick_IRQn 1 */ } diff --git a/exp1/MDK-ARM/exp1.uvprojx b/exp1/MDK-ARM/exp1.uvprojx index 3658537..78970cc 100644 --- a/exp1/MDK-ARM/exp1.uvprojx +++ b/exp1/MDK-ARM/exp1.uvprojx @@ -1,7 +1,10 @@ - - + + + 2.1 +
### uVision Project, (C) Keil Software
+ exp1 @@ -16,28 +19,28 @@ Keil.STM32G4xx_DFP.1.5.0 https://www.keil.com/pack/ IRAM(0x20000000-0x2001FFFF) IROM(0x8000000-0x801FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") TZ - - - + + + 0 - - - - - - - - - - + + + + + + + + + + $$Device:STM32G473CBTx$CMSIS\SVD\STM32G473xx.svd 0 0 - - - - - + + + + + 0 0 @@ -52,15 +55,15 @@ 1 1 1 - + 1 0 0 0 0 - - + + 0 0 0 @@ -69,8 +72,8 @@ 0 0 - - + + 0 0 0 @@ -79,15 +82,15 @@ 0 1 - - + + 0 0 0 0 1 - + 0 @@ -101,8 +104,8 @@ 0 0 3 - - + + 0 @@ -135,11 +138,11 @@ 1 BIN\UL2V8M.DLL - - - - - + + + + + 0 @@ -172,7 +175,7 @@ 0 0 "Cortex-M4" - + 0 0 0 @@ -306,7 +309,7 @@ 0x0 - + 1 @@ -333,9 +336,9 @@ 0 0 - + USE_HAL_DRIVER,STM32G473xx - + ../Core/Inc;../Drivers/STM32G4xx_HAL_Driver/Inc;../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32G4xx/Include;../Drivers/CMSIS/Include @@ -351,10 +354,10 @@ 0 1 - - - - + + + + @@ -364,15 +367,15 @@ 0 1 0 - - - - - - - - - + + + + + + + + + @@ -410,6 +413,11 @@ 1 ../Core/Src/stm32g4xx_hal_msp.c + + variable.h + 5 + ..\Core\Inc\variable.h + @@ -508,17 +516,18 @@ + - + - + - + - + -
+