Systick系统滴答时钟
Systick.h
#ifndef __SYSTICK_H
#define __SYSTICK_H
#include "stm32f10x.h"
void SysTick_Init(void);
void Delay_ms(__IO u32 nTime);
#endif /* __SYSTICK_H */
Systick.c
#include "SysTick.h"
static __IO u32 TimingDelay;
/*初始化 SysTick*/
void SysTick_Init(void)
{
/* SystemFrequency / 1000 1ms中断一次
* SystemFrequency / 100000 10us中断一次
* SystemFrequency / 1000000 1us中断一次
*/
if (SysTick_Config(SystemFrequency / 1000))
{
/* Capture error */
while (1);
}
}
/*us延时程序,10us为一个单位 */
void Delay_ms(__IO u32 nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* 获取节拍程序,在 SysTick 中断函数 SysTick_Handler()调用 */
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}