<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32 延時函數(shù)封裝

          STM32 延時函數(shù)封裝

          作者: 時間:2012-09-10 來源:網(wǎng)絡(luò) 收藏

          /*---------------------------------

          本文引用地址:http://www.ex-cimer.com/article/148436.htm

          模塊

          說明:只需在工程中加入delay.c和delay.h

          文件,即可用 Delayms(__IO uint32_t nTime);

          Delayus(__IO uint32_t nTime)

          -----------------------------------*/

          #ifndef __DELAY_H

          #define __DELAY_H

          #include stm32f10x.h

          /*---------------------------------

          描 述:參數(shù)1即為1ms,1000即為1s;只有幾

          us的誤差;

          -----------------------------------*/

          extern void Delayms(__IO uint32_t nTime);

          /*---------------------------------

          描 述:參數(shù)1即為1us,1000即為1ms;只有幾

          us的誤差;

          -----------------------------------*/

          extern void Delayus(__IO uint32_t nTime);

          /*---------------------------------

          名:調(diào)整形式的delaynus,

          描 述:參數(shù)1即為1us,1000即為1ms;

          -----------------------------------*/

          extern void delay_nus(unsigned long n);

          /*---------------------------------

          函數(shù)名:調(diào)整形式的delaynms函數(shù),

          描 述:參數(shù)1即為1ms,1000即為1s;

          -----------------------------------*/

          extern void delay_nms(unsigned long n);

          #endif

          C 函數(shù)

          /*---------------------------------

          延時模塊函數(shù)

          說明:只需在工程中加入delay.c和delay.h

          文件,即可用 Delayms(__IO uint32_t nTime);

          Delayus(__IO uint32_t nTime)

          -----------------------------------*/

          #includedelay.h

          static __IO uint32_t TimingDelay;

          /* Private function prototypes -----------------------------------------------*/

          /*---------------------------------

          函數(shù)名:ms延時函數(shù)

          描 述:參數(shù)1即為1ms,1000即為1s;只有幾

          us的誤差;

          -----------------------------------*/

          void Delayms(__IO uint32_t nTime)

          {

          while(SysTick_Config(SystemCoreClock/1000));

          TimingDelay = nTime;

          while(TimingDelay != 0);

          SysTick->CTRL=0x00; //關(guān)閉計數(shù)器

          SysTick->VAL =0X00; //清空計數(shù)器

          }

          /*---------------------------------

          函數(shù)名:us延時函數(shù)

          描 述:參數(shù)1即為1us,1000即為1ms;只有幾

          us的誤差;

          -----------------------------------*/

          void Delayus(__IO uint32_t nTime)

          {

          while(SysTick_Config(SystemCoreClock/1000000));

          TimingDelay = nTime;

          while(TimingDelay != 0);

          SysTick->CTRL=0x00; //關(guān)閉計數(shù)器

          SysTick->VAL =0X00; //清空計數(shù)器

          }

          /*---------------------------------

          函數(shù)名:延時輔助函數(shù)

          描 述:

          -----------------------------------*/

          void TimingDelay_Decrement(void)

          {

          if (TimingDelay != 0x00)

          {

          TimingDelay--;

          }

          }

          /*---------------------------------

          函數(shù)名:systick的中斷函數(shù)

          描 述:參數(shù)1即為1us,1000即為1ms;只有幾

          us的誤差;

          -----------------------------------*/

          void SysTick_Handler(void)

          {

          TimingDelay_Decrement();

          }

          /*---------------------------------

          函數(shù)名:延時調(diào)整形式的delaynus函數(shù),

          描 述:參數(shù)1即為1us,1000即為1ms;

          -----------------------------------*/

          void delay_nus(unsigned long n)

          {

          unsigned long j;

          while(n--)

          {

          j=12;

          while(j--);

          }

          }

          /*---------------------------------

          函數(shù)名:延時調(diào)整形式的delaynms函數(shù),

          描 述:參數(shù)1即為1ms,1000即為1s;

          -----------------------------------*/

          void delay_nms(unsigned long n)

          {

          while(n--)

          delay_nus(1030);

          }



          關(guān)鍵詞: 封裝 函數(shù) 延時 STM32

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();