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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)產(chǎn)生掃頻信號(hào)400Hz~3KHz-----占空比50%的方波

          單片機(jī)產(chǎn)生掃頻信號(hào)400Hz~3KHz-----占空比50%的方波

          作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò) 收藏
          發(fā)一個(gè)產(chǎn)生掃頻信號(hào)的程序,大家參考一下

          //單片機(jī)晶振12MHz,這個(gè)程序如果要提高掃頻信號(hào)輸出的頻率關(guān)鍵的一句是

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

          //dataLoad=10000/(2*(4+i));//153個(gè)時(shí)鐘周期

          //記該指令的執(zhí)行時(shí)間是N個(gè)時(shí)鐘周期

          //該程序可以輸出地掃頻信號(hào)的最高頻率為fosc/(2*N*12)

          //如果想要提高掃頻信號(hào)的最高頻率使用時(shí)鐘頻率更高的芯片,或者可以

          //更改這條語(yǔ)句,使之執(zhí)行時(shí)間縮短

          //這個(gè)程序的編程思路如下:

          //定時(shí)器0負(fù)責(zé)輸出方波的定時(shí),輸入指定頻率的方波

          //定時(shí)器1負(fù)責(zé)0.1秒定時(shí),如果時(shí)間到,則改變

          //定時(shí)器0的控制的輸出方波的頻率

          #include
          sbit outWave=P0^0;
          #define uchar unsigned char
          #define uint unsigned int
          uchar t1Counter;//the times of t1 interrupt
          uint dataLoad; //the reset data of the time0, volatile variable.
          bit t1Int;// the flag of time1 interrupt

          //定時(shí)器0初始化
          void InitTimer0(){
          TMOD|=0x01;//定時(shí)器方式1
          ET0=1;//允許T0中斷
          TH0=(65536-dataLoad)/256;//定時(shí)器初值10ms
          TL0=(65536-dataLoad)%256;
          TR0=1;//啟動(dòng)T0
          }
          //定時(shí)器0中斷
          void Time0Int() interrupt 1{
          TH0=(65536-dataLoad)/256;//定時(shí)器初值10ms
          TL0=(65536-dataLoad)%256;
          outWave=!outWave;
          }
          //定時(shí)器1初始化
          void InitTimer1(){
          TMOD|=0x10;//定時(shí)器方式1
          ET1=1;//允許T1中斷
          TH1=(65536-50000)/256;//定時(shí)50ms
          TL1=(65536-50000)%256;
          TR1=1;//啟動(dòng)T1
          }
          //time1
          void Time1Int() interrupt 3{
          TH1=(65536-50000)/256;//定時(shí)50ms
          TL1=(65536-50000)%256;
          t1Counter++;
          }
          //主函數(shù)
          void main(){
          uchar i; //the number of the frequency
          dataLoad=1250;//400hz,2.5ms
          InitTimer0();//定時(shí)器0初始化
          InitTimer1();
          EA=1;//開(kāi)總中斷
          PT1=1;
          while(1)
          {
          //if(t1Int)
          //{
          //t1Int=0;
          //t1Counter++;
          if(t1Counter==2){//3
          t1Counter=0; //2
          //change the dataLoad
          dataLoad=10000/(2*(4+i));//153個(gè)時(shí)鐘周期
          i++;
          i=i%26;
          }
          // }
          }
          }



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