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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 關(guān)于51單片機(jī)電子時鐘精度的問題

          關(guān)于51單片機(jī)電子時鐘精度的問題

          作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
          前幾天用STC89C52單片機(jī)制作了一個電子時鐘,經(jīng)過一段時間的實(shí)驗(yàn),發(fā)現(xiàn)時間精度存在誤差,一分鐘慢4秒左右。

          這可了不得,十分鐘就要慢40秒,一天下來不得慢半96分鐘?。?!

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

          這個單片機(jī)晶振頻率為11.0592mhz,和大部分時鐘的晶振頻率相同,應(yīng)該沒有問題。

          后天考慮到源代碼:

          定時器中斷函數(shù)里:

          void t0(void) interrupt 1 using 0 {	tcount++;if(tcount==4000){tcount=0;second++;if(second==60){second=0;minute++;if(minute==60){minute=0;hour++;if(hour==24){hour=0;}}}P1=~P1;}}
          interrupt 后面的數(shù)字簡單的說就是中斷服務(wù)函數(shù)的代號
          0代表外中斷0
          1代表定時計(jì)數(shù)器0中斷
          2代表外中斷1
          3代表定時計(jì)數(shù)器1中斷
          4代表串行口中斷
          所以interrupt 1代表定時計(jì)數(shù)器產(chǎn)生中斷后就轉(zhuǎn)到這個函數(shù)里面執(zhí)行。

          代碼其實(shí)還挺簡單,每中斷4000下將產(chǎn)生1秒。

          等等...

          每4000下的中斷為1秒,那么原因很有可能在這里。

          試著將tcount==3600,和秒表對比發(fā)現(xiàn)竟然每一分鐘快了1秒左右。

          bingo!問題的確出在tcount的取值上面,將tcount的數(shù)值改為3700,和秒表對比發(fā)現(xiàn),秒數(shù)沒有誤差,有誤差的應(yīng)該就是毫秒級吧。

          void t0(void) interrupt 1 using 0 {	tcount++;if(tcount==3700){tcount=0;second++;if(second==60){second=0;minute++;if(minute==60){minute=0;hour++;if(hour==24){hour=0;}}}P1=~P1;}}

          這樣就解決了時鐘精度的問題。



          關(guān)鍵詞: 51單片機(jī)電子時鐘精

          評論


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