39 lines
821 B
C
39 lines
821 B
C
#include "config.h" //全局声明
|
|
|
|
void delay_init(void)
|
|
{
|
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);//用于配置延时函数
|
|
}
|
|
//延时函数:毫秒级别
|
|
void delay_ms(uint32_t nms)
|
|
{
|
|
uint32_t tmp;
|
|
while(nms--)
|
|
{
|
|
SysTick->LOAD = 168000000/8/1000; //计数初值,延时1ms
|
|
SysTick->VAL = 0; //清空当前值
|
|
SysTick->CTRL |= 0x1; //开始计数
|
|
while ((SysTick->CTRL & 0x00010000)==0);
|
|
|
|
SysTick->VAL = 0; //清空当前值
|
|
SysTick->CTRL &= 0; //关闭计数
|
|
}
|
|
}
|
|
|
|
//延时函数:微秒级别
|
|
void delay_us(uint32_t nus)
|
|
{
|
|
uint32_t tmp;
|
|
while(nus--)
|
|
{
|
|
SysTick->LOAD = 168000000/8/1000000; //计数初值,延时1us
|
|
SysTick->VAL = 0; //清空当前值
|
|
SysTick->CTRL |= 0x1; //开始计数
|
|
while ((SysTick->CTRL & 0x00010000)==0);
|
|
SysTick->VAL = 0; //清空当前值
|
|
SysTick->CTRL &= 0; //关闭计数
|
|
}
|
|
|
|
}
|
|
|
|
|