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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)音樂-輸出口P0.4 STC89C52RC測試通過

          單片機(jī)音樂-輸出口P0.4 STC89C52RC測試通過

          作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          /**
          * 編寫時(shí)間: 2013.05.16
          * 作 者: 小蘇
          * 函數(shù)功能: 單片機(jī)音樂-世上只有媽媽好
          * 使用說明: 輸出口P0.4 STC89C52RC測試通過
          ******************************************************************************/
          #include
          #define uchar unsigned char
          sbit beep=P0^4; //定義蜂鳴器輸出端口
          uchar timer0h,timer0l,time;
          //世上只有媽媽好 數(shù)據(jù)表
          code uchar sszymmh[]={6,2,3,5,2,1,3,2,2,5,2,2,1,3,2,6,2,1,5,2,1,
          6,2,4,3,2,2,5,2,1,6,2,1,5,2,2,3,2,2,1,2,1,
          6,1,1,5,2,1,3,2,1,2,2,4,2,2,3,3,2,1,5,2,2,
          5,2,1,6,2,1,3,2,2,2,2,2,1,2,4,5,2,3,3,2,1,
          2,2,1,1,2,1,6,1,1,1,2,1,5,1,6,0,0,0
          };
          // 音階頻率表 高八位
          code uchar FREQH[]={0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8,
          0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC,0xFC, //1,2,3,4,5,6,7,8,i
          0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,
          0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,} ;
          // 音階頻率表 低八位
          code uchar FREQL[]={0x42,0xC1,0x17,0xB6,0xD0,0xD1,0xB6,
          0x21,0xE1,0x8C,0xD8,0x68,0xE9,0x5B,0x8F, //1,2,3,4,5,6,7,8,i
          0xEE,0x44, 0x6B,0xB4,0xF4,0x2D,
          0x47,0x77,0xA2,0xB6,0xDA,0xFA,0x16,};
          void delay(uchar t) // 延時(shí)函數(shù)
          {
          uchar t1;
          unsigned long t2;
          for(t1=0;t1
          {
          for(t2=0;t2<8000;t2++);
          }
          TR0=0;
          }
          void song() // 音樂處理函數(shù)
          {
          TH0=timer0h;
          TL0=timer0l;
          TR0=1;
          delay(time);
          }
          /******************************************************************
          主函數(shù)
          ******************************************************************/
          void main(void)
          {
          uchar k,i;
          TMOD=1; //置CT0定時(shí)工作方式1
          EA=1;
          ET0=1; //IE=0x82 //CPU開中斷,CT0開中斷
          while(1)
          {
          i=0;
          while(i<100) //音樂數(shù)組長度 ,唱完從頭再來
          {
          k=sszymmh[i]+7*sszymmh[i+1]-1;
          timer0h=FREQH[k];
          timer0l=FREQL[k];
          time=sszymmh[i+2];
          i=i+3;
          song();
          }
          }
          }
          void t0int() interrupt 1 //定時(shí)器中斷函數(shù)
          {
          TR0=0;
          beep=!beep;
          TH0=timer0h;
          TL0=timer0l;
          TR0=1;
          }


          評論


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