bsp_SysTick.h
#ifndef __SYSTICK_H
#define __SYSTICK_H
#include "stm32f4xx.h"
void SysTick_Init(void); //定义初始化函数
void Delay_us(__IO u32 nTime); //单位10us
//#define Delay_ms(x) Delay_us(100*x) //可自由配置中断时间,当前中断时间为1ms
#endif /* __SYSTICK_H */
bsp_SysTick.c
/**
******************************************************************************
* SysTick系统滴答时钟10us中断函数库,中断时间可自由配置,常用的有1us,10us,1ms中断
******************************************************************************
*/
#include "./systick/bsp_SysTick.h"
static __IO u32 TimingDelay;
/**
* 启动系统滴答定时器SysTick
*/
void SysTick_Init(void)
{
/* SystemFrequency / 1000 1ms中断一次
* SystemFrequency / 100000 10us中断一次
* SystemFrequency / 1000000 1us中断一次
*/
if (SysTick_Config(SystemCoreClock / 10000))
{
/* Capture error */
while (1);
}
}
/**
* @brief us延时程序,10us为一个单位
* @arg nTime: Delay_us( 1 ) 则实现延时为 1 * 10us = 10us
*/
void Delay_us(__IO u32 nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief 获取节拍程序
* @attention 在SYSTick中断函数SysTick_Handler()调用
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/*********************************************END OF FILE**********************/
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』