#include "gd32f4xx.h"
/**
* @Author: ChenSong
* @description: 毫秒级延时函数,使用系统的滴答定时器实现
* @param {volatile uint32_t} cnt 延时时间(单位:毫秒)
* @return {*}
*/
void bsp_delay_ms(volatile uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/1000;
while(SysTick->VAL > u32end)
{
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* @Author: ChenSong
* @description: 微秒级延时函数,使用系统的滴答定时器实现
* @param {volatile uint32_t} cnt 延时时间(单位:微秒)
* @return {*}
*/
void bsp_delay_us(volatile uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/1000000;
while(SysTick->VAL > u32end)
{
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_43848900/article/details/144846230
|