• STM32学习笔记之Systick


    Systick实验中,Systick用来定时。来看看程序中什么地方出现过Systick相关的语句。

    main.c:
      /* SysTick end of count event each 1ms with input clock equal to 9MHz (HCLK/8, default) */
      SysTick_SetReload(9000);

      /* Enable SysTick interrupt */
      SysTick_ITConfig(ENABLE);

      /*******************************************************************************
    * Function Name  : Delay
    * Description    : Inserts a delay time.
    * Input          : nTime: specifies the delay time length, in milliseconds.
    * Output         : None
    * Return         : None
    *******************************************************************************/
    void Delay(u32 nTime)
    {
      /* Enable the SysTick Counter */
      SysTick_CounterCmd(SysTick_Counter_Enable);
      TimingDelay = nTime;

      while(TimingDelay != 0);

      /* Disable SysTick Counter */
      SysTick_CounterCmd(SysTick_Counter_Disable);
      /* Clear SysTick Counter */
      SysTick_CounterCmd(SysTick_Counter_Clear);
    }

    /*******************************************************************************
    * Function Name  : TimingDelay_Decrement
    * Description    : Decrements the TimingDelay variable.
    * Input          : None
    * Output         : TimingDelay
    * Return         : None
    *******************************************************************************/
    void TimingDelay_Decrement(void)
    {
      if (TimingDelay != 0x00)
      {
        TimingDelay--;
      }
    }

    stm32f10x_it.c:
    void SysTickHandler(void)
    {
    TimingDelay_Decrement();
    }

    Systick的应用:
    初始化时:
    首先我们要确定Systick的时钟源,再确定重装载值,如果用中断方式,
    这里可以打开Systick中断始能。

    定时运行时:
    使能Systick时钟,判断systick定时到0,到0以后,失能Systick时钟,再清0重载寄存器。

  • 相关阅读:
    CF949C Data Center Maintenance 题解
    P1438 无聊的数列 题解
    CF620E New Year Tree 题解
    结构体优先队列的定义
    CF464E The Classic Problem 题解
    CF427C Checkposts
    CF161D Distance in Tree 题解
    P4375 [USACO18OPEN]Out of Sorts G 题解
    SCI, SCIE, 和ESCI的区别
    Matlab画图中图的方法
  • 原文地址:https://www.cnblogs.com/hnrainll/p/1933348.html
Copyright © 2020-2023  润新知