SysTick定时器和delay延迟函数 - SysTickCounterCmd - Systick_SetReload - Systick_ITconfig

//初始化相关的模块
Systick_SetReload(9000); //设定systick达到1ms计数结束
Systick_ITconfig(ENABLE); //时能systick中断

//中断处理
void SystickHandler(void)
{
 if (TimingDelay != 0x00)        //TimingDelay定义为volative的全局变量
 {
  TimingDelay--;
 }
}

//延时代码
void Delay(int32u nTime)
{
 SysTickCounterCmd(SysTick_Counter_Enable);   //使能Systick;
 TimingDelay = nTime;   //读取延时时间
 while (TimingDelay != 0)
 {
              //不做操作
 }
 SysTick_CounterCmd(SysTick_Counter_Disable);   //关闭systick
 SysTick_CounterCmd(SysTick_Counter_Clear);    //清除systick
 
}

你可能感兴趣的:(systick,delay)