How to use SysTick precision delay and tick timer in HAL library

After knowing the position of systick in the system, we come to understand the realization of systick. Here is just an example to illustrate the use of systick. It has four registers, the author lists them:

  •     SysTick->CTRL, --Control and status registers
  •     SysTick->LOAD, --Reload register
  •     SysTick->VAL, --current value register
  •    SysTick->CALIB, --calibration value register    
void Delay_us(unsigned int nTime)
{
         SysTick->LOAD = 72*nTime;
         SysTick->CTRL =SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
         while(!(SysTick->CTRL&SysTick_CTRL_COUNTFLAG_Msk));
         SysTick->CTRL =~SysTick_CTRL_ENABLE_Msk;
}

 

链接:https://pan.baidu.com/s/1NAVhBSyy47t_82qnShwY0w 
提取码:pdtg 

 

 

Guess you like

Origin blog.csdn.net/weixin_41865104/article/details/89743493