基于51單片機(jī)的音樂程序.doc
《基于51單片機(jī)的音樂程序.doc》由會員分享,可在線閱讀,更多相關(guān)《基于51單片機(jī)的音樂程序.doc(10頁珍藏版)》請?jiān)谘b配圖網(wǎng)上搜索。
基于51單片機(jī)的按鍵切換播放音樂原理圖:引腳說明:共5個按鍵,分別接51單片機(jī)的P0P4引腳,前4個按鍵控制播放設(shè)置好的四首音樂,第5個按鍵用來關(guān)閉音樂。按鍵采用中斷方式,任意時(shí)刻按下任意按鍵則立即進(jìn)入所按按鍵的功能;蜂鳴器接單片機(jī)的P3.6口。仿真說明:使用proteus仿真,晶振:12MHZ。程序代碼如下:/*12Mhz晶振工作*/#include #define uint unsigned int#define uchar unsigned charsbit voice=P36;uchar code sound1=0xff,0x40,0x80,0x30,0x40,0x2b,0x40,0x26,0x80,0x24,0x10,0x26,0x40,0x30,0x40,0x2b,0x80,0x30,0x40,0x39,0x40,0x30,0xc0,0x40,0x80,0x30,0x40,0x2b,0x40,0x26,0x40,0x26,0x20,0x24,0x20,0x20,0x40,0x30,0x40,0x24,0x80,0x26,0x10,0x20,0x40,0x2b,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x2b,0xc0,0x26,0x80,0x20,0x40,0x19,0x40,0x19,0x80,0x1c,0x10,0x1c,0x80,0x20,0x40,0x20,0x20,0x1c,0x20,0x19,0x40,0x1c,0x20,0x20,0x20,0x26,0xc0,0x24,0x80,0x24,0x10,0x20,0x40,0x1c,0x40,0x20,0x40,0x24,0x20,0x26,0x20,0x2b,0x80,0x33,0x40,0x33,0x20,0x39,0x20,0x40,0x40,0x39,0x40,0x30,0xc0,0x18,0x80,0x1c,0x80,0x24,0x80,0x20,0x10,0x1c,0x80,0x19,0x40,0x19,0x20,0x19,0x20,0x19,0x40,0x1c,0x20,0x20,0x20,0x26,0xc0,0x18,0x80,0x1c,0x80,0x24,0x80,0x20,0x10,0x1c,0x80,0x1c,0x40,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x24,0x20,0x26,0x20,0xff,0x20,0x00;/同一首歌*/uchar code sound2=0xff,0x18,0x40,0x1c,0x20,0x18,0x20,0x13,0x40,0x13,0x20,0x15,0x20,0x13,0x20,0x15,0x20,0x13,0x20,0x15,0x20,0x18,0x20,0x19,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x19,0x20,0x18,0x20,0x15,0x40,0x10,0x80,0x13,0x10,0x10,0x40,0x15,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x13,0x10,0x18,0x10,0x1c,0x10,0x26,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x15,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x18,0x10,0x1c,0x10,0x24,0x10,0x30,0x10,0x18,0x10,0x1c,0x10,0x24,0x10,0x30,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x19,0x10,0x19,0x10,0x20,0x10,0x2b,0x10,0x19,0x10,0x18,0xc0,0xff,0x40,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x40,0x2b,0x10,0x2b,0x20,0x26,0x20,0x26,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x2b,0x10,0x2b,0x20,0x2b,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x2b,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x26,0x20,0x1c,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x40,0x2b,0x10,0x2b,0x20,0x26,0x20,0x20,0x80,0x40,0x10,0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x2b,0x40,0x2b,0x10,0x2b,0x20,0x2b,0x20,0x2b,0x40,0x30,0x10,0x30,0x20,0x39,0x20,0x30,0x80,0x30,0x10,0x18,0x20,0x19,0x20,0x18,0x20,0x1c,0x20,0x18,0x40,0x1c,0x10,0x1c,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x1c,0x10,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x20,0x10,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x40,0xff,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x18,0x40,0x18,0x10,0x18,0x20,0x18,0x20,0x18,0x40,0x1c,0x10,0x1c,0x20,0x18,0x20,0x1c,0x80,0x20,0x10,0x20,0x20,0x30,0x20,0x18,0x20,0x19,0x20,0x18,0x20,0x19,0x20,0x1c,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x1c,0x40,0x1c,0x10,0x1c,0x20,0x1c,0x20,0x1c,0x40,0x20,0x10,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x26,0x40,0xff,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x1c,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x18,0x80,0xff,0x40,0xff,0x40,0xff,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x1c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x30,0xc0,0x30,0x80,0x30,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x18,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x18,0x20,0x18,0x20,0x15,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x13,0x20,0x15,0x20,0x15,0x20,0x18,0x20,0x1c,0x20,0x18,0x20,0x15,0x40,0x30,0xc0,0xff,0x40,0x00; /愛情轉(zhuǎn)移*/uchar code sound3=0xff,0x40,0x10,0x39,0x10,0x30,0x10,0x2b,0x10,0x26,0x20,0x20,0x10,0x20,0x10,0x20,0x30,0x18,0x10,0x19,0x20,0x1c,0x20,0x20,0x20,0x20,0x40,0x1c,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,0x24,0x10,0x26,0x10,0x26,0x10,0x2b,0x20,0x30,0x10,0x39,0x20,0x30,0x10,0x30,0x10,0x30,0x20,0x20,0x20,0x24,0x10,0x26,0x10,0x2b,0x10,0x30,0x10,0x33,0x10,0x40,0x10,0x39,0x20,0x39,0xc0,0xff,0x20,0x26,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x18,0x30,0x19,0x10,0x1c,0x10,0x1c,0x10,0x20,0x10,0x1c,0x20,0x20,0x20,0x1c,0x20,0x1c,0x10,0x18,0x10,0x19,0x20,0x1c,0x10,0x20,0x10,0x1c,0x60,0x26,0x20,0x20,0x20,0x1c,0x10,0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x10,0x18,0x30,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x18,0x10,0x15,0x30,0x13,0x20,0x13,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x13,0x10,0x13,0x60,0x15,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x18,0x10,0x15,0x10,0x15,0x60,0x15,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x18,0x20,0x19,0x10,0x1c,0x10,0x1c,0x60,0xff,0x20,0x13,0x20,0x15,0x10,0x18,0x10,0x15,0x10,0x18,0x10,0x15,0x20,0x18,0x10,0x15,0x10,0x15,0x20,0x18,0x20,0x18,0x10,0x10,0x30,0x10,0xc0,0x18,0x20,0x15,0x20,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x13,0x10,0x15,0x10,0x15,0x10,0x10,0x30,0x10,0x20,0x13,0x10,0x10,0x10,0x0e,0x10,0x0e,0x10,0x0e,0x10,0x0e,0x10,0x10,0x20,0x13,0x10,0x15,0x10,0x13,0x60,0x15,0x20,0x13,0x20,0x15,0x20,0x18,0x10,0x1c,0x10,0x1c,0x40,0x18,0x20,0x19,0x10,0x1c,0x10,0x1c,0x40,0xff,0x20,0x0e,0x20,0x10,0x20,0x13,0x20,0x15,0x40,0x18,0x20,0x15,0x20,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0xc0,0x30,0x40,0x2b,0x30,0x26,0x10,0x39,0x40,0xff,0x20,0x30,0x10,0x39,0x10,0x33,0x10,0x30,0x10,0x2b,0x20,0x2b,0x20,0x30,0x10,0x2b,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x1c,0x10,0x20,0x10,0x2b,0x10,0x26,0x10,0x26,0x80,0x18,0x10,0x19,0x10,0x1c,0x10,0x1c,0x10,0x19,0x20,0x26,0x20,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0xc0,0xff,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x15,0x20,0x13,0x40,0x15,0x20,0x18,0x20,0x1c,0x40,0x1c,0xc0,0x00;/最后一次的溫柔*/uchar code sound4=0xff,0x40,0x30,0x30,0x80,0x30,0x30,0x30,0x80,0x26,0x40,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x30,0x30,0x26,0x80,0x20,0x30,0x1c,0xc0,0x1c,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x39,0x30,0x39,0x80,0x40,0x30,0x30,0xc0,0x30,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x1c,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x20,0x30,0x1c,0xc0,0x1c,0x80,0x18,0x30,0x20,0x80,0x26,0x30,0x26,0x80,0x30,0x30,0x2b,0x80,0x30,0x30,0x2b,0x80,0x26,0x30,0x30,0x80,0x39,0x30,0x39,0x80,0x40,0x30,0x30,0xc0,0x30,0xc0,0x00;/友誼地久天長*/*uchar code sound=0xff,0x20,0x60,0x26,0x20,0x20,0x40,0x20,0x20,0x1c,0x20,0x18,0x40,0x18,0x20,0x1c,0x20,0x20,0x80,0x20,0x60,0x1c,0x20,0x20,0x20,0x1c,0x10,0x20,0x10,0x26,0x20,0x2b,0x20,0x20,0x30,0x1c,0x10,0x20,0x20,0x26,0x20,0x2b,0x80,0xff,0x20,0x20,0x20,0xff,0x20,0x20,0x20,0x1c,0x40,0x20,0x40,0x18,0x30,0x1c,0x10,0x20,0x20,0x26,0x20,0x2b,0x80,0xff,0x20,0x20,0x20,0xff,0x20,0x20,0x20,0x26,0x40,0x2b,0x20,0x30,0x20,0x30,0xc0,0xff,0x40,0x00;/中華民謠*/uchar zdjs=0,jp,p,a;uint dpjs;void del(uchar yj) uchar yj2=2; while(yj!=0) while(yj2!=0) yj2-; yj2=2; yj-; void delay0() uchar u=20; while(u-);void play() uchar yj; dpjs=0; while(a) zdjs=0; dpjs+; if(p=1) yj=sound1dpjs; dpjs+; jp=sound1dpjs; if(p=2) yj=sound2dpjs; dpjs+; jp=sound2dpjs; if(p=3) yj=sound3dpjs; dpjs+; jp=sound3dpjs; if(p=4) yj=sound4dpjs; dpjs+; jp=sound4dpjs; while(zdjs!=jp) if(yj!=0xff) if(yj!=0) voice=!voice; del(yj); else dpjs=0; break; else voice=0; del(jp); void init() TMOD=0x01; IE=0x82; TH0=0xd8; TL0=0xef; TR0=1; EX0=1; IT0=1; EA=1;void main(void) init(); a=1; p=1; while(1) play(); void init_0(void) interrupt 0 uchar q;q=P1;if(q!=0xff) delay0(); q=P1; if(q!=0xff) zdjs=0; dpjs=0; jp=0;switch(q) case 0xfe: a=1;p=1;break; case 0xfd: a=1;p=2;break; case 0xfb: a=1;p=3;break; case 0xf7: a=1;p=4;break; case 0xef: a=0;break; void time0(void) interrupt 1 TH0=0xd8; TL0=0xef; zdjs+;聲明:歡迎學(xué)習(xí)與制作;轉(zhuǎn)載請注明出處!- 1.請仔細(xì)閱讀文檔,確保文檔完整性,對于不預(yù)覽、不比對內(nèi)容而直接下載帶來的問題本站不予受理。
- 2.下載的文檔,不會出現(xiàn)我們的網(wǎng)址水印。
- 3、該文檔所得收入(下載+內(nèi)容+預(yù)覽)歸上傳者、原創(chuàng)作者;如果您是本文檔原作者,請點(diǎn)此認(rèn)領(lǐng)!既往收益都?xì)w您。
下載文檔到電腦,查找使用更方便
9.9 積分
下載 |
- 配套講稿:
如PPT文件的首頁顯示word圖標(biāo),表示該P(yáng)PT已包含配套word講稿。雙擊word圖標(biāo)可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國旗、國徽等圖片,僅作為作品整體效果示例展示,禁止商用。設(shè)計(jì)者僅對作品中獨(dú)創(chuàng)性部分享有著作權(quán)。
- 關(guān) 鍵 詞:
- 基于 51 單片機(jī) 音樂程序
鏈接地址:http://m.italysoccerbets.com/p-6639855.html