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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 6位數(shù)顯頻率計數(shù)器實驗方法

          6位數(shù)顯頻率計數(shù)器實驗方法

          作者: 時間:2011-12-04 來源:網(wǎng)絡(luò) 收藏

          1.任務(wù)

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

          利用AT89S51單片機的T0、T1的定時功能,來完成對輸入的信號進行計數(shù),計數(shù)的結(jié)果通過8位動態(tài)數(shù)碼管顯示出來。要求能夠?qū)?-250KHZ的信號進行準確計數(shù),計數(shù)誤差不超過±1HZ。

          2.電路原理圖

          3.系統(tǒng)板上硬件連線

          (1).把“單片機系統(tǒng)”區(qū)域中的P0.0-P0.7與“動態(tài)數(shù)碼顯示”區(qū)域中的ABCDEFGH端口用8芯排線連接。

          (2).把“單片機系統(tǒng)”區(qū)域中的P2.0-P2.7與“動態(tài)數(shù)碼顯示”區(qū)域中的S1S2S3S4S5S6S7S8端口用8芯排線連接。

          (3).把“單片機系統(tǒng)”區(qū)域中的P3.4(T0)端子用導(dǎo)線連接到“頻率產(chǎn)生器”區(qū)域中的WAVE端子上。

          4.程序設(shè)計內(nèi)容

          (1).定時/T0和T1的工作方式設(shè)置,由圖可知,T0是工作在計數(shù)狀態(tài)下,對輸入的頻率信號進行計數(shù),但對工作在計數(shù)狀態(tài)下的T0,最大計數(shù)值為fOSC/24,由于fOSC=12MHz,因此:T0的最大計數(shù)頻率為250KHz。對于頻率的概念就是在一秒只數(shù)脈沖的個數(shù),即為頻率值。所以T1工作在定時狀態(tài)下,每定時1秒中到,就停止T0的計數(shù),而從T0的計數(shù)單元中讀取計數(shù)的數(shù)值,然后進行數(shù)據(jù)處理。送到數(shù)碼管顯示出來。

          (2).T1工作在定時狀態(tài)下,最大定時時間為65ms,達不到1秒的定時,所以采用定時50ms,共定時20次,即可完成1秒的定時功能。

          5.C語言源程序

          C程序

          #include AT89X51.h>

          unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

          unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};

          unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};

          unsigned char temp[8];

          unsigned char dispcount;

          unsigned char T0count;

          unsigned char timecount;

          bit flag;

          unsigned long x;

          void main(void)

          {

          unsigned char i;

          TMOD=0x15;

          TH0=0;

          TL0=0;

          TH1=(65536-4000)/256;

          TL1=(65536-4000)%6;

          TR1=1;

          TR0=1;

          ET0=1;

          ET1=1;

          EA=1;

          while(1)

          {

          if(flag==1)

          {

          flag=0;

          x=T0count*65536+TH0*256+TL0;

          for(i=0;i8;i++)

          {

          temp[i]=0;

          }

          i=0;

          while(x/10)

          {

          temp[i]=x;

          x=x/10;

          i++;

          }

          temp[i]=x;

          for(i=0;i6;i++)

          {

          dispbuf[i]=temp[i];

          }

          timecount=0;

          T0count=0;

          TH0=0;

          TL0=0;

          TR0=1;

          }

          }

          }

          void t0(void) interrupt 1 using 0

          {

          T0count++;

          }

          void t1(void) interrupt 3 using 0

          {

          TH1=(65536-4000)/256;

          TL1=(65536-4000)%6;

          timecount++;

          if(timecount==250)

          {

          TR0=0;

          timecount=0;

          flag=1;

          }

          P0=dispcode[dispbuf[dispcount]];

          P2=dispbit[dispcount];

          dispcount++;

          if(dispcount==8)

          {

          dispcount=0;

          }

          }



          評論


          相關(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); })();