用SysTick作为定时时钟,生成延时函数Delay(N)
- UID
- 856476
|
用SysTick作为定时时钟,生成延时函数Delay(N)
通过配置SysTick,设定1ms产生一次中断,在中断函数里对N减一,在Delay(N)中循环检测N是否为0,不为0则进行循环等待;若为0则关闭SysTick时钟,退出函数。延时时间将不随系统时钟频率改变。
if (SysTick_Config(SystemCoreClock / 1000))
{
/* Capture error */
while (1);
}
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
|
|
|
|
|
|