基础版本
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#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; //关闭计数
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user