蜂鳴器響聲三種音樂_第1頁(yè)
蜂鳴器響聲三種音樂_第2頁(yè)
蜂鳴器響聲三種音樂_第3頁(yè)
蜂鳴器響聲三種音樂_第4頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、/ 這是 單片機(jī)音樂代碼生成器 生成的代碼兩只蝴蝶音樂編程程序:#include #define uchar unsigned charsbit beeplO=P3W;/輸出為P1.5可以修改成其它10 口uchar m,n;uchar code T492=0,0, 0xF8,0x8B,0xF8,0xF2,0xF9,0x5B,0xF9,0xB7,0xFA,0x14,0xFA,0x66,0xFA,0xB9,0xFB,0x03 ,0xFB,0x4A,0xFB,0x8F,0xFB,0xCF,0xFC,0x0B,0xFC,0x43,0xFC,0x78,0xFC,0xAB,0xFC,0xDB,0xFD,

2、0x08,0xFD,0x33,0xFD,0x5B,0xFD,0x8 1,0xFD,0xA5,0xFD,0xC7,0xFD,0xE7,0xFE,0x05,0xFE,0x21,0xFE,0x3C,0xFE,0x55,0xFE,0x6D,0xFE,0x84,0xFE,0x99,0xFE,0xAD,0xFE,0xC0 ,0xFE,0x02,0xFE,0xE3,0xFE,0xF3,0xFF,0x02,0xFF,0x10,0xFF,0x1D,0xFF,0x2A,0xFF,0x36,0xFF,0x42,0xFF,0x4C,0xFF,0x56,0xFF,0x60, 0xFF,0x69,0xFF,0x71,0x

3、FF,0x79,0xFF,0x81;uchar code music2=0,4, 23,4,21,4,23,16,23,4,21,4,23,4,21,4,19,16,16,4,19,4,21,8,21,4,23,4,21,4,19 ,4,16,4,19,4,14,24,23,4,21,4,23,16,23,4,21,4,23,4,21,4,19,24,16,4,19,4,21,8,21,4,23,4,21,4,19 ,4,16,4,19,4,21,24,23,4,21,4,23,16,23,4,21,4,23,4,21,4,19,16,16,4,19,4,21,8,21,4,23,4,21,4

4、,19 ,4,16,4,19,4,14,24,23,4,26,4,26,16,26,4,28,4,26,4,23,24,21,4,23,4,21,8,21,4,23,4,21,4,19,4,16 ,4,16,2,19,2,19,24,0,20,26,4,26,4,28,4,31,4,30,4,30,4,28,4,23,4,21,4,21,4,23,16,0,4,23,4,23,4,26,4 ,28,8,28,12,16,4,23,4,21,4,21,24,23,4,26,4,26,4,23,4,26,8,0,4,31,8,30,4,28,4,30,4,23,8,0,4,28,4,28,4, 3

5、0,4,28,4,26,4,23,4,21,8,23,4,21,4,23,4,26,16,0xFF,0xFF;void delay(uchar p)uchar i,j;for(;p0;p-)for(i=181;i0;i-)for(j=181;j0;j-);void pause() uchar i,j;for(i=150;i0;i-) for(j=150;j0;j-);void T0_int() interrupt 1beepIO=!beepIO;TH0=Tm0; TL0=Tm1;void main()uchar i=0;TMOD=0x01; EA=1; ET0=1;while(1) m=mus

6、ici0;n=musici1;if(m=0x00)TR0=0;delay(n);i+;else if(m=0xFF)TR0=0;delay(30);i=0;else if(m=musici+10)TR0=1;delay(n);TR0=0;pause();i+;else TR0=1;delay(n);i+; 豬八戒背媳婦 #include #define uchar unsigned char #define uint unsigned int sbit fm=P3W;蜂鳴器控制端口 uchar timeh,timel;/ 用于存放定時(shí)器的高 8 位和低 8 位 uchar code zbjbx

7、f=/ 定義豬八戒背媳婦的簡(jiǎn)譜數(shù)組高低0x64,0xA3,0xC1,0xA2,0x62,0x84,0x61,0x81,0x61,0xA4,0xA1, 0x91,0xA1,0x81,0x64,0xA3,0xC1,0xD2,0xD2,0xD2,0xA2,0xC4, 0xA1,0xC1,0xA1,0xC1,0xD2,0xD2,0xD2,0xA2,0xC4,0xC2,0x62, 0xC2,0x62,0xA2,0xA2,0x84,0x94,0x94,0x92,0x81,0x91, 0xA2, 0xC2,0xD4,0xE4,0xA4,0xE4,0xA2,0xE2,0xA2,0xE2,0xA2, 0xA2,

8、 0x84,0x94,0x94,0x92,0x81,0x91,0xA2,0xC2,0xD8; / 適合 12M 的晶振定時(shí)器初值表, 8 位分開 uchar code chuzhi=0xff,0xff,0xFC,0x8E,0xFC, 0xED,0xFD,0x43,0xFD,0x6A,0xFD,0xB3,0xFD,0xF3,0xFE,0x2D,0xFE, 0x47,0xFE,0x76,0xFE,0xA1,0xFE,0xC7,0xFE,0xD9,0xFE,0xF9,0xFF,0x16;void timer0() interrupt 1/ 定時(shí)器 0 中斷服務(wù)程序TH0=timeh; / 將 tim

9、eh 賦給計(jì)時(shí)器的高 8 位TL0=timel; / 將 timel 賦給計(jì)時(shí)器的低 8 位 fm=fm; / 定時(shí)器每次到時(shí)將蜂鳴器反相void delay(uint z) /延時(shí)165MS,即十六分音符uint y;for(z;z0;z-) for(y=19000;y0;y-);/ 大致時(shí)間void delay1(uint z) / 延時(shí) 1MSuint y;for(z;z0;z-) for(y=112;y0;y-);/ 大致時(shí)間void main()uint temp; / 存放簡(jiǎn)譜數(shù)組中的每一個(gè)音符的臨時(shí)變量 uchar i=0;uchar jp; /jp 用于取出 temp 中的高

10、8 位和低 8 位 TMOD=0x01;/ 設(shè)置定時(shí)器 T0 工作于方式 1 IE=0x82; / 允許 T0 中斷while(1)temp=zbjbxfi; if(temp=0xff) break;jp=temp/16;if(jp!=0) timeh=chuzhijp*2;/ 構(gòu)造定時(shí)器初值高 8 位 timel=chuzhijp*2+1; / 構(gòu)造定時(shí)器初值低 8 位 TR0=1; / 開定時(shí)器else TR0=0; / 關(guān)定時(shí)器 fm=1; / 關(guān)蜂鳴器 delay(temp%16); / 取數(shù)的低 4 位 ,節(jié)拍(音符總時(shí)延) TR0=0; / 唱完一個(gè)音停 5MSfm=1; dela

11、y1(5); /TR0=1; i+;TR0=0; / 關(guān)定時(shí)器 fm=1; / 關(guān)蜂鳴器生日快樂:#include #define uint unsigned int#define uchar unsigned charsbit beep = P3A6;uchar code SONG_TONE=212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126,159,142,159,0;uchar code SONG_LONG=9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0;/ 延時(shí)void DelayMS(uint x)uchar t;while(x-) for(t=0;t120;t+);void PlayMusic()uint i=0,j,k;while(SONG_LONGi!=0|SONG_TONEi!=0) / 播放各個(gè)音符, SONG_LO

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論