延时函数delay_us

/*
void delay_us(uint32_t udelay)
定义:微秒延时函数
参数;
//udelay--输入--微秒
*/
void delay_us(uint32_t udelay)
{
  uint32_t startval,tickn,delays,wait;
 
  startval = SysTick->VAL;
  tickn = HAL_GetTick();
  delays =udelay * 48; //sysc / 1000 * udelay;和系统时钟有关
  if(delays > startval)
    {
      while(HAL_GetTick() == tickn)
        {
        }
      wait = 48000 + startval - delays;
      while(wait < SysTick->VAL)
        {
        }
    }
  else
    {
      wait = startval - delays;
      while(wait < SysTick->VAL && HAL_GetTick() == tickn)
        {
        }
    }
}

 

你可能感兴趣的:(公共-功能函数(软件+硬件))