zoukankan      html  css  js  c++  java
  • 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重载寄存器。

  • 相关阅读:
    动态规划最大利润的问题
    【转】mysql基础汇总
    mac使用frida
    Mac 下python3 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法
    mac使用jadx逆向app
    python桶排序代码
    requests_html使用asyncio
    async for的使用
    [转载]微信企业号:企业客户的移动应用入口
    微信服务号、订阅号、企业号差别
  • 原文地址:https://www.cnblogs.com/hnrainll/p/1933348.html
Copyright © 2011-2022 走看看