#include "delay.h"
//volite u32 TimingDelay define the volite
__IO u32 TimingDelay;
/**
* @brief Configures the SysTick.
* @param None
* @retval None
*/
void SysTick_Init(void)
{
if (SysTick_Config(SystemCoreClock / 1000000))
{
while(1);
}
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
/**
* @brief Define the us delay function.
* @param 传入延迟时间
* @retval None
*/
void delay_us(__IO u32 nTime)
{
TimingDelay = nTime;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(TimingDelay != 0);
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
/**
* @brief Define the ms delay function.
* @param 传入延迟时间
* @retval None
*/
void delay_ms(__IO u32 nTime)
{
TimingDelay = nTime * 1000;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
while(TimingDelay != 0);
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
/**
* @brief Define the decreasing function.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}