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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR C語句運行時間測試程序源代碼

          AVR C語句運行時間測試程序源代碼

          作者: 時間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
          整個工程下載:
          http://www.rayfile.com/zh-cn/files/b8f67659-d773-11df-b350-0015c55db73d/f0ec1fdf/
          核心代碼:
          /********** AVR 運行時間測試程序 **********
          * 版本.........: 1.0
          * 作者.........: 陳利棟
          * 目標(biāo).........: ATmega128
          * 文件名.......: main.c
          * 編譯器.......: IAR for AVR V5.5
          * 創(chuàng)建時間.....: 2010.10.14
          * 最后修改.....: 2010.10.14
          ******************************************/
          #include "main.h"

          intputchar(intc)
          {
          returnuart_putchar(c);
          }

          volatileunsignedintTimerOverflowCount=0;

          intmain(void)
          {
          unsignedlongTimerCount=0;

          UART_Init();
          printf("*********** 運行時間測試 ***********rn");
          printf("Build: %s %srn",__DATE__,__TIME__);
          printf("時鐘頻率: %fMHzrn",(float)F_CPU/1000000);

          TCCR1B_CS10=1;// 定時器1使能計數(shù),無分頻
          TIMSK_TOIE1=1;// 定時器1使能溢出中斷
          __enable_interrupt();// 總中斷使能
          TimerOverflowCount=0;// 溢出計數(shù)清零
          TCNT1=0;// 計數(shù)器清零


          /* 此處插入要運行的代碼 */
          /* 代碼開始 */
          _delay_us(123456);
          /* 代碼結(jié)束 */

          TCCR1B_CS10=0;// 定時器1停止計數(shù) 花費3個時鐘周期
          TimerCount=TCNT1;
          TimerCount|=((unsignedlong)TimerOverflowCount<<16);
          TimerCount-=3;// 關(guān)閉定時器的時間
          TimerCount-=(50*TimerOverflowCount);// 溢出中斷花費的時間

          printf("消耗時鐘周期數(shù)...: %ld 0x%lxrn",TimerCount,TimerCount);
          printf("消耗時間(單位: s): %lfrn",(double)1*TimerCount/F_CPU);
          printf("消耗時間(單位:ms): %lfrn",(double)1000*TimerCount/F_CPU);
          printf("消耗時間(單位:us): %lfrn",(double)1000000*TimerCount/F_CPU);
          printf("消耗時間(單位:ns): %lfrn",(double)1000000000*TimerCount/F_CPU);

          while(1);
          }

          #pragma vector = TIMER1_OVF_vect
          __interruptvoidTimer1_Overflow(void)
          {
          TimerOverflowCount++;
          }
          測試效果:


          關(guān)鍵詞: AVRC語句運行時

          評論


          技術(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); })();