Files

64 lines
2.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/***********************************************************************!
* 技术讨论:QQ群 123763203
* 官网 www.navota.com
*
* @file delay.c
* @brief systic函数库
* @author Navota
* @date 2018-3-1
************************************************************************/
#include "delay.h"
//延时驱动C 文件
/***********************************************************************************************
功能:初始化延时模块
形参:0
返回:0
详解:此函数用于初始化延时模块,使用函数时必须调用。否则会造成延时函数出错
************************************************************************************************/
void DelayInit(void)
{
SysTick->CTRL = 0;//选取systick的时钟为内核时钟/16
}
/***********************************************************************************************
功能:US级延时函数
形参:US 需要延时多少US
返回:0
详解:裸机下的延时US
************************************************************************************************/
void DelayUs(uint32_t us)
{
uint32_t temp;
SysTick->LOAD = (us*BUS_CLK_HZ/10000)/(1600); //时间加载
SysTick->VAL = 0x00; //清空计数器
SysTick->CTRL |= 0x01 ; //开始倒数
do
{
temp = SysTick->CTRL;
}while(temp & 0x01 && !(temp & (1<<16))); //等待时间到达
SysTick->CTRL &= ~0x01; //关闭计数器
}
/***********************************************************************************************
功能:MS级延时函数
形参:MS需要延时多少MS
返回:0
详解:裸机下的延时MS
************************************************************************************************/
void DelayMs(uint32_t ms)
{
uint32_t temp;
uint16_t i;
for(i = 0;i < ms;i++) //延时 MS
{
SysTick->LOAD = (BUS_CLK_HZ/1000)/16; //时间加载1ms
SysTick->VAL = 0x00; //清空计数器
SysTick->CTRL |= 0x01; //开始倒数
do
{
temp = SysTick->CTRL;
}while(temp & 0x01 && !(temp & (1<<16))); //等待时间到达
SysTick->CTRL &= ~0x01; //关闭计数器
}
}