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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 89S51演奏生日快樂的歌曲c程序

          89S51演奏生日快樂的歌曲c程序

          作者: 時間:2016-11-18 來源:網(wǎng)絡 收藏
          程序描述:這個程序利用89S51演奏生日快樂的歌曲 */

          /* ***************************************************** */

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

          #include

          void delay(unsigned char n); //函數(shù)delay()存在 文件delay.c

          code unsigned song[]={

          0x82,0x01,0x81,0x94,0x84,0xB4,0xA4,0x04,0x82,0x01,0x81,

          0x94,0x84,0xC4,0xB4,0x04, 0x82,0x01,0x81,0xF4,0xD4,0xB4,

          0xA4,0x94,0xE2,0x01,0xE1,0xD4,0xB4,0xC4,0xB4,0x04,

          0x82,0x01,0x81,0x94,0x84,0xB4,0xA4,0x04,0x82,0x01,0x81,

          0x94,0x84,0xC4,0xB4,0x04, 0x82,0x01,0x81,0xF4,0xD4,0xB4,

          0xA4,0x94,0xE2,0x01,0xE1,0xD4,0xB4,0xC4,0xB4,0x04,

          0x00};

          code int note[]={

          0x0000,0xFB03,0xFB8E,0xFC0B,0xFC43,0xFCAB,0xFD08,0xFD32,

          0xFD81,0xFDC7,0xFE05,0xFE21,0xFE55,0xFE83,0xFE99,0xFEC0};

          unsigned char i=0;

          unsigned char hi_note,low_note;

          static void timer1_isr(void) interrupt TF1_VECTOR using 2

          {

          TR1=0;

          TL1=low_note;

          TH1=hi_note;

          TR1=1;

          P3_7=3_7;

          }

          static void timer1_initialize(void)

          {

          EA=0;

          TR1=0;

          TMOD = 0X10;

          ET1=1;

          EA=1;

          }

          void singing()

          {

          unsigned char beat,temp;

          i=0;

          do {

          temp=song[i]; // 讀出樂譜的一個byte

          if (temp==0) { // 如果是0就表示音樂結束

          TR1=0; // 停止計時計數(shù)器1

          return; // 返回

          }

          beat=temp & 0x0f; //取出低階的4位,這是拍子

          temp=(temp >> 4) & 0x0f; //取出高階4位當成音符的頻率

          if (temp==0) TR1=0; //如果拍子是0就表示休止符

          else {

          hi_note=note[temp] >> 8; //根據(jù)音符的頻率得到Timer1計數(shù)值

          low_note=note[temp] & 0x00FF;

          TR1=1; //啟動計時計數(shù)器1

          }

          delay(beat); // 延遲拍子的時間

          i++;

          } while(1);

          }

          void main (void) {

          timer1_initialize();

          do {

          singing();

          } while (1); // 無窮循環(huán)

          }



          評論


          技術專區(qū)

          關閉
          看屁屁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); })();