<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> STM32 >> 瀏覽文章

        stm32 SysTick的詳細配置

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年03月28日   【字體:

        一、文件main.c
         
        #include "stm32f10x.h"
        #include "SysTick.h"
        /*
         * 函數名:main
         * 描述  :主函數
         * 輸入  :無
         * 輸出  :無
         */
        int main(void)
        {
        /* 配置SysTick 為10us中斷一次 */
            SysTick_Init();
            for(;;)
            {
                Delay_us(50000);    // 50000 * 10us = 500ms
            }
           
        }
         
        二、文件SysTick..c對SysTick_Init進行初始化
         
        void SysTick_Init(void)
        {
        /* SystemFrequency / 1000    1ms中斷一次
         * SystemFrequency / 100000 10us中斷一次
         * SystemFrequency / 1000000 1us中斷一次
         */
        //if (SysTick_Config(SystemFrequency / 100000))// ST3.0.0庫版本
            if (SysTick_Config(SystemCoreClock / 100000))// ST3.5.0庫版本
            {
                while (1);/* Capture error */
            }
            SysTick->CTRL &= ~ SysTick_CTRL_ENABLE_Msk;// 關閉滴答定時器
        }
         
        三、文件system_stm32f10x.c中定義SystemCoreClock
         
        uint32_t SystemCoreClock         = SYSCLK_FREQ_72MHz;        /*!< System Clock Frequency (Core Clock) */
         
        四、文件core_cm3.h里的函數SysTick_Config
         
        static __INLINE uint32_t SysTick_Config(uint32_t ticks)
        {
          if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */                                                            
          SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */
          NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */
          SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
          SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
                           SysTick_CTRL_TICKINT_Msk   |
                           SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
          return (0);                                                  /* Function successful */
        }
         
        五、文件core_cm3.h
         
        #define SysTick_CTRL_CLKSOURCE_Pos          2                                   /*!< SysTick CTRL: CLKSOURCE Position */
        #define SysTick_CTRL_CLKSOURCE_Msk         (1ul << SysTick_CTRL_CLKSOURCE_Pos)  /*!< SysTick CTRL: CLKSOURCE Mask */
         
        #define SysTick_CTRL_TICKINT_Pos            1                                   /*!< SysTick CTRL: TICKINT Position */
        #define SysTick_CTRL_TICKINT_Msk           (1ul << SysTick_CTRL_TICKINT_Pos)    /*!< SysTick CTRL: TICKINT Mask */
         
        #define SysTick_CTRL_ENABLE_Pos             0                                   /*!< SysTick CTRL: ENABLE Position */
        #define SysTick_CTRL_ENABLE_Msk            (1ul << SysTick_CTRL_ENABLE_Pos)     /*!< SysTick CTRL: ENABLE Mask */
         
        /* SysTick Reload Register Definitions */
        #define SysTick_LOAD_RELOAD_Pos             0                                    /*!< SysTick LOAD: RELOAD Position */
        #define SysTick_LOAD_RELOAD_Msk            (0xFFFFFFul << SysTick_LOAD_RELOAD_Pos)
         
        六、文件SysTick.c
         
        static __IO u32 TimingDelay;
         
        void Delay_us(__IO u32 nTime)
        {
            TimingDelay = nTime;
            SysTick->CTRL |=  SysTick_CTRL_ENABLE_Msk;// 使能滴答定時器
            while(TimingDelay != 0);
        }
         
        七、文件SysTick.c
         
        void TimingDelay_Decrement(void)
        {
            if (TimingDelay != 0x00)
            {
                TimingDelay--;
            }
        }
         
        八、文件stm32f10x_it.c
         
        SystemCoreClock / 100000=10us中斷一次,TimingDelay為總中斷次數
        extern void TimingDelay_Decrement(void);
        void SysTick_Handler(void)
        {
            TimingDelay_Decrement();
        }

         

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮