GD32 延时函数实现:100ms 延时代码示例
要在 GD32 上实现 100ms 的延时函数,可以使用 SysTick 定时器来实现。以下是一个简单的实现示例:
#include "gd32f30x.h"
static __IO uint32_t delay_count;
void delay_init(void)
{
/* 配置 SysTick 定时器为 0.1ms */
if (SysTick_Config(SystemCoreClock / 10000))
{
while(1);
}
}
void delay_ms(uint32_t ms)
{
delay_count = ms;
while(delay_count != 0);
}
void SysTick_Handler(void)
{
if (delay_count != 0x00)
{
delay_count--;
}
}
在使用延时函数之前,需要先调用 delay_init() 函数进行初始化。然后可以通过调用 delay_ms(100) 来实现 100ms 的延时。
请注意,该延时函数是基于 SysTick 定时器的中断实现的,因此在使用该延时函数时,需要注意不要在中断中使用,否则会导致延时不准确。
原文地址: https://www.cveoy.top/t/topic/palb 著作权归作者所有。请勿转载和采集!