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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC16F877A TIMER1計(jì)數(shù)操作

          PIC16F877A TIMER1計(jì)數(shù)操作

          作者: 時(shí)間:2016-11-11 來(lái)源:網(wǎng)絡(luò) 收藏
          /**********************

          Title:PIC16F877A TIMER1計(jì)數(shù)操作
          Author:hnrain
          Date:2010-12-28

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

          使用前置分頻器
          T1CKPS1 T1CKPS1
          0 0 1 分頻 TMR1時(shí)鐘為晶振時(shí)鐘/(4*1)
          0 1 2 分頻 TMR1時(shí)鐘為晶振時(shí)鐘/(4*2)
          1 0 4 分頻 TMR1時(shí)鐘為晶振時(shí)鐘/(4*4)
          1 1 8 分頻 TMR1時(shí)鐘為晶振時(shí)鐘/(4*8)
          TMR1是16位寬度的TMR1由2個(gè)8位的可讀寫(xiě)的寄存器TMR1H和TMR1L組成。

          TMR1有專(zhuān)門(mén)的啟??刂莆籘MR1ON,通過(guò)軟件可以任意啟動(dòng)或暫停TMR1計(jì)數(shù)功能。

          T1CON:TIMER1 CONTROL REGISTER

          bit7-6 unimplemented :Read as ‘0’

          bit5-4 T1CKPS1:T1CKPS0:Timer1 input Clock Prescale Select bits

          11=1:8 prescale value

          10=1:4 prescale value

          01=1:2 prescale value

          00=1:1 prescale value

          bit3 T1OSCEN:Timer1 Oscillator Enable Control bit

          1 = Oscillator is enable

          0 = Oscillator is shut-off

          bit2 T1SYNC:Timer1 External Clock Input Synchronization Control bit

          when TMR1CS = 1

          1= Do not synchronize external clock input

          0= Synchronize external clock input

          when TMR1CS = 0

          This bit is ignored .Timer1 uses the internal clock when TMR1CS = 0.

          bit1 TMR1CS:Timer1 Clock Source Select bit

          1 = External clock from pin RC0/T1OSO/T1CKI

          0 = Internal clock

          bit0 TMR1ON:Timer1 on bit

          1 = enables timer1

          0 = stops timer1
          說(shuō)明:作用在TMR1的計(jì)數(shù)狀態(tài),計(jì)數(shù)信號(hào)從RC0/T1CKI輸入,
          當(dāng)來(lái)一個(gè)上升沿時(shí),采集到一個(gè)有效的信號(hào),計(jì)數(shù)到TMR1L,TMR1H中。
          當(dāng)計(jì)滿時(shí)就會(huì)產(chǎn)生中斷信號(hào)。
          ***********************/
          #include
          #include "../head/config.h"

          __CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);

          void main(void)
          {
          T1CKPS0 = 0;
          T1CKPS1 = 0;//不分頻

          TMR1L = (65536 - 1)%256;//TMR1L,TMR1H賦初值
          TMR1H = (65536 - 1)/256;
          T1SYNC = 1;//TMR1異步計(jì)數(shù)器
          TMR1CS = 1;
          GIE = 1;//打開(kāi)全局中斷
          PEIE = 1;//打開(kāi)外部中斷
          TMR1IE = 1;//TMR1中斷打開(kāi)
          TMR1ON = 1;
          PORTD = 0x00;
          TRISD = 0x00;
          while(1){}
          }

          void interrupt ISR(void)
          {
          TMR1L = (65536 - 1)%256;//重新賦值
          TMR1H = (65536 - 1)/256;
          if(TMR1IE && TMR1IF)
          {
          TMR1IF = 0;
          PORTD = ~PORTD;
          }
          }



          評(píng)論


          技術(shù)專(zhuān)區(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); })();