TA的每日心情 | 开心 2020-11-23 14:54 |
---|
签到天数: 19 天 连续签到: 1 天 [LV.4]偶尔看看III
|
和Stm32类似,但是注意一点的是,中断函数必须要写!否则不起作用!
1.systick.c文件如下:- /**
- ******************************************************************************
- * @file SysTick/Systick_demo/systick.c
- * @author MCU SD
- * @version V1.0.0
- * @date 15-Jul-2015
- * @brief The SysTick configuration file.
- ******************************************************************************
- */
- #include "gd32f20x.h"
- #include "systick.h"
- static __IO uint32_t TimingDelay;
- /**
- * @brief Configure SysTick.
- * @param None
- * @retval None
- */
- void SysTick_Configuration(void)
- {
- /* Setup SysTick Timer for 1000Hz interrupts */
- if (SysTick_Config(SystemCoreClock / 1000))
- {
- /* Capture error */
- while (1);
- }
- }
- /**
- * @brief Insert a delay time.
- * @param nTime: specifies the delay time length, in milliseconds.
- * @retval None
- */
- void Delay_1ms(uint32_t nTime)
- {
- TimingDelay = nTime;
- while(TimingDelay != 0);
- }
- /**
- * @brief Decrement the TimingDelay variable.
- * @param None.
- * @retval None
- */
- void TimingDelay_Decrement(void)
- {
- if (TimingDelay != 0x00)
- {
- TimingDelay--;
- }
- }
- /******************* (C) COPYRIGHT 2015 GIGADEVICE *****END OF FILE****/
复制代码 2. 在gd32f20x_it.c文件中:- void SysTick_Handler(void)
- {
- TimingDelay_Decrement();
- }
复制代码 这就OK了,main函数中先初始化,后调用即可!- while(1)
- {
- EvbLedControl(LED2, LED_ON);
- EvbLedControl(LED3, LED_ON);
- Delay_1ms(1000);
-
- EvbLedControl(LED2, LED_OFF);
- EvbLedControl(LED3, LED_OFF);
-
- Delay_1ms(1000);
-
- }
复制代码 |
|