單片機(jī)課程設(shè)計(jì)電子音調(diào)發(fā)生器_第1頁(yè)
單片機(jī)課程設(shè)計(jì)電子音調(diào)發(fā)生器_第2頁(yè)
單片機(jī)課程設(shè)計(jì)電子音調(diào)發(fā)生器_第3頁(yè)
單片機(jī)課程設(shè)計(jì)電子音調(diào)發(fā)生器_第4頁(yè)
單片機(jī)課程設(shè)計(jì)電子音調(diào)發(fā)生器_第5頁(yè)
已閱讀5頁(yè),還剩34頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、 單片機(jī)課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告電子音調(diào)發(fā)生器姓名: 日期: 2009年6月29日星期一目錄(一)實(shí)驗(yàn)?zāi)康?(二)設(shè)計(jì)任務(wù)及要求2(三)工作原理及設(shè)計(jì)思路2(四)實(shí)現(xiàn)功能設(shè)計(jì)3(五)軟件設(shè)計(jì)3(六)電路設(shè)計(jì)35(七)調(diào)試36(八)實(shí)驗(yàn)體會(huì)37(一)實(shí)驗(yàn)?zāi)康? 了解計(jì)算機(jī)發(fā)聲原理。2 熟悉定時(shí)器和鍵盤(pán)掃描電路的工作原理及編程方法。(二)設(shè)計(jì)任務(wù)及要求利用實(shí)驗(yàn)平臺(tái)上的開(kāi)關(guān)k0-k7和蜂鳴器設(shè)計(jì)電子音調(diào)發(fā)生器,要求:1利用實(shí)驗(yàn)平臺(tái)上開(kāi)關(guān)k0-k7進(jìn)行音調(diào)選擇,即撥動(dòng)不同的開(kāi)關(guān)產(chǎn)生不同的音調(diào),依次撥動(dòng)K0K7,蜂鳴器發(fā)出1234567i八個(gè)音調(diào)。2編寫(xiě)2支歌曲,并可進(jìn)行選擇播放。(三)工作原理及設(shè)計(jì)思路音節(jié)由

2、不同頻率的方波產(chǎn)生,音節(jié)與頻率的關(guān)系如表1所示。要產(chǎn)生音頻方波,只要算出某一音頻的周期(1/頻率),然后將此周期除以2,即為半周期的時(shí)間。利用計(jì)時(shí)器計(jì)時(shí)此半周期時(shí)間,每當(dāng)計(jì)時(shí)到后就將輸出方波的I/0反相,然后重復(fù)計(jì)時(shí)此半周期時(shí)間再對(duì)I/O反相,就可在I/O腳得到此頻率的方波。在ZKS-03實(shí)驗(yàn)儀上,產(chǎn)生方波的I/O腳選用P1.7,通過(guò)跳線選擇器JP1將單片機(jī)的P1.7與蜂鳴器的驅(qū)動(dòng)電路相連。這樣P1.7輸出不同頻率的方波,蜂鳴器便會(huì)發(fā)出不同的聲音。另外,音樂(lè)的節(jié)拍是由延時(shí)實(shí)現(xiàn)的,如果1拍為0.4秒,1/4拍是0.1秒。只要設(shè)定延時(shí)時(shí)間,就可求得節(jié)拍的時(shí)間。延時(shí)作為基本延時(shí)時(shí)間,節(jié)拍值只能是它的

3、整數(shù)倍, 每個(gè)音節(jié)相應(yīng)的定時(shí)器初值X可按下法計(jì)算: (1/2)*(1/f)=(12/fose)*(216-x)即 x=216-(fose/24f)其中f:音調(diào)頻率,當(dāng)晶振fose=11.0592MHz時(shí),音節(jié)“1”相應(yīng)的定時(shí)器初值為x,則可得x=63777D=F921H 其它的可同樣求得。 表1 音調(diào)頻率(Hz)X(HEX)1262F9212294F9E13330FA8C4349FAD85392FB686440FBE97494FC5Bi523FC8F(四)實(shí)現(xiàn)功能設(shè)計(jì)實(shí)現(xiàn)兩個(gè)主要功能:電子琴與音樂(lè)播放;一個(gè)輔助功能:在液晶上顯示相關(guān)信息。1、電子琴:4*4的矩陣16個(gè)按鍵,按鍵0實(shí)現(xiàn)兩個(gè)功能的

4、切換,其余按鍵分別發(fā)出音調(diào) 低音5、6、7,中音1、2、3、4、5、6、7,高音1、2、3、4、5。發(fā)音的同時(shí)在液晶顯示屏上顯示出對(duì)應(yīng)的音調(diào)。2、音樂(lè)播放:按鍵0實(shí)現(xiàn)兩個(gè)功能的切換,按鍵1實(shí)現(xiàn)播放類型選擇(單曲循環(huán)播放、所有循環(huán)播放),其余按鍵分別對(duì)應(yīng)一首歌。目前已經(jīng)有9首歌。播放的同時(shí),在液晶上顯示出歌名。(五)軟件設(shè)計(jì)根據(jù)要實(shí)現(xiàn)的功能,流程圖如下:開(kāi)始系統(tǒng)初始化判斷按鍵判斷按鍵電子琴液晶顯示錄音調(diào)整時(shí)鐘功能選擇音樂(lè)#include <AT89X52.H>#include <intrins.h>#define nop _nop_() #define ucha

5、r unsigned char #define uint unsigned int#define PAI_BASE 15#define MUSIC_NUM 9#define SCAN_CYCLE 500#define BEEP P3_3/*液晶顯示相關(guān)變量*/sbit LCD_RS = P27; sbit LCD_RW = P26;sbit LCD_EN = P25; static uchar th0_f; /在中斷中裝載的 T0 的值高 8 位static uchar tl0_f; /在中斷中裝載的 T0 的值低 8 位static timebuffer,Record_counter,Rec

6、ord_flag=0;static uchar key2,key=16,scounter=0,Record_time;static uchar s_musicCounter=0x00,s_tableCounter;bit Rplay_flag=0;bit K0_flag=0;bit Music_flag0;bit Music_flag=0;bit Freq_flag=0;bit disptime_flag=0;bit musicAutoFlag=0;/sbit BEEP = P3_3; /喇叭輸出腳/延時(shí)子程序1void delay(int ms) int i; while(ms-) for(

7、i = 0; i< 250; i+) _nop_(); _nop_(); _nop_(); _nop_(); /*/* */*檢查L(zhǎng)CD忙狀態(tài) */*lcd_busy為1時(shí),忙,等待。lcd-busy為0時(shí),閑,可寫(xiě)指令與數(shù)據(jù)。 */* */*/bit lcd_busy() bit result; LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; _nop_(); _nop_(); _nop_(); _nop_(); result = (bit)(P0&0x80); LCD_EN = 0; return result; /*/* */*寫(xiě)指令數(shù)據(jù)到LCD *

8、/*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。 */* */*/void lcd_wcmd(uchar cmd) while(lcd_busy(); LCD_RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); P0 = cmd; _nop_(); _nop_(); _nop_(); _nop_(); LCD_EN = 1; _nop_(); _nop_(); _nop_(); _nop_(); LCD_EN = 0; /*/* */*寫(xiě)顯示數(shù)據(jù)到LCD */*RS=H,RW=L,E=高脈沖,D0-D7=數(shù)據(jù)。 */* */*/void

9、lcd_wdat(uchar dat) while(lcd_busy(); LCD_RS = 1; LCD_RW = 0; LCD_EN = 0; P0 = dat; _nop_(); _nop_(); _nop_(); _nop_(); LCD_EN = 1; _nop_(); _nop_(); _nop_(); _nop_(); LCD_EN = 0; /*/* */* 設(shè)定顯示位置 */* */*/void lcd_pos(uchar pos) lcd_wcmd(pos|0x80); /數(shù)據(jù)指針=80+地址變量/*/* */* LCD初始化設(shè)定 */* */*/void lcd_init

10、() delay(15); /等待LCD電源穩(wěn)定 lcd_wcmd(0x38); /16*2顯示,5*7點(diǎn)陣,8位數(shù)據(jù) delay(5); lcd_wcmd(0x38); delay(5); lcd_wcmd(0x38); delay(5); lcd_wcmd(0x0c); /顯示開(kāi),關(guān)光標(biāo) delay(5); lcd_wcmd(0x06); /移動(dòng)光標(biāo) delay(5); lcd_wcmd(0x01); /清除LCD的顯示內(nèi)容 delay(5);/*/* */* 清屏子程序 */* */*/void lcd_clr() lcd_wcmd(0x01); /清除LCD的顯示內(nèi)容 delay(5)

11、;/靜態(tài)顯示字符串void lcd_string(char *strpoint) /*在當(dāng)前顯示位置顯示LCD 字符串*/ register i=0;while(strpointi!=0) lcd_wdat(strpointi);i+;/*/*Constant Tables*/const char code c_music1=0x82,0x01,0x81,0x94,0x84, /*生日快樂(lè)歌*/ 0xb4,0xa4,0x04,0x82,0x01,0x81,0x94,0x84,0xc4,0xb4,0x04,0x82,0x01,0x81,0xf4,0xd4,0xb4,0xa4,0x94,0xe2,

12、0x01,0xe1,0xd4,0xb4,0xc4,0xb4,0x04,0x00;const char code c_music2=0x62, 0x52, /*兩只蝴蝶*/ 0x64, 0x64, 0x02, 0x52, 0x62, 0x52, 0x44, 0x44, 0x04, 0x22, 0x42, 0x54, 0x52, 0x62, 0x52, 0x42, 0x22, 0x42, 0x14, 0x14, 0x04, 0x62, 0x52, 0x64, 0x64, 0x02, 0x52, 0x62, 0x52, 0x44, 0x44, 0x04, 0x22, 0x42, 0x54, 0x52

13、, 0x62, 0x52, 0x42, 0x22, 0x42, 0x54, 0x54, 0x04, 0x62, 0x82,0x84, 0x84, 0x02, 0x82, 0x92, 0x82,0x64, 0x64, 0x04, 0x52, 0x52,0x54, 0x52, 0x62, 0x52, 0x42, 0x22, 0x91, 0x41,0x42, 0x42, 0x44, 0x44, 0x44, 0x02, 0x82, 0x82, 0x92, 0xb2, 0xa2, 0xa2, 0x92, 0x64, 0x52, 0x62, 0x64, 0x64, 0x02, 0x62, 0x62, 0x

14、82, 0x94, 0x94, 0x02, 0x22, 0x62, 0x52, 0x54, 0x54, 0x04, 0x62, 0x82, 0x82, 0x62, 0x84, 0x02, 0xb2, 0xb2, 0xa2, 0x92, 0xa2, 0x64, 0x02, 0x92, 0x92, 0xa2, 0x92, 0x82, 0x62, 0x52, 0x52, 0x62, 0x52, 0x62, 0x84, 0x84, 0x02, 0x82, 0x82, 0x92, 0x92, 0x82, 0x62, 0x52, 0x52, 0x12, 0x12, 0x22, 0x44, 0x44, 0x

15、44, 0x44, 0x00;const char code c_music3=0x04, 0x42, 0x41, 0x51, 0x62, 0x62, 0x52, 0x41, 0x51, 0x54, 0x02, 0x41, 0x51, /*老鼠愛(ài)大米*/ 0x62, 0x62, 0x52, 0x42, 0x44, 0x02, 0x11, 0x21, 0x14, 0x11, 0x11, 0x21, 0x41, 0x44, 0x02, 0x42, 0x42, 0x42, 0x42, 0x41, 0x51, 0x54, 0x42, 0x51, 0x61, 0x62, 0x62, 0x82, 0x91

16、, 0x51, 0x54, 0x62, 0x51, 0x41, 0x42, 0x42, 0x52, 0x61, 0x81, 0x84, 0x02, 0x81, 0x81, 0x92, 0x41, 0x41, 0x42, 0x61, 0x01, 0x52, 0x42, 0x42, 0x51, 0x41, 0x44, 0x44, 0x44, 0x62, 0x61, 0x81, 0x82, 0x81, 0x81, 0x82, 0x81, 0x91, 0x94, 0x62, 0x52, 0x42, 0x42, 0x42, 0x51, 0x61, 0x64, 0x02, 0x61, 0x81, 0x82

17、, 0x82, 0x82, 0x91, 0xb1, 0xb2, 0x92, 0x82, 0x62,0x52, 0x42, 0x42, 0x22, 0x54, 0x02, 0x61, 0x81,0x82, 0x82, 0x81, 0x92, 0x81, 0x94, 0x62, 0x52, 0x42, 0x42, 0x42, 0x51, 0x61, 0x64, 0x02, 0x61, 0x81, 0x82, 0x82, 0x82, 0x91, 0xb1, 0xb2, 0x92, 0x82, 0x61, 0x51, 0x52, 0x52, 0x54, 0x54, 0x41, 0x62, 0x71,

18、0x62, 0x52, 0x54, 0x54, 0x62, 0x51, 0x41, 0x44, 0x62, 0x51, 0x41, 0x44, 0x62, 0x52, 0x62, 0x42, 0x62, 0x91, 0x81, 0x84, 0x02, 0x61, 0x81, 0x92, 0x91, 0x81, 0x82, 0x91, 0x81, 0x84, 0x61, 0x51, 0x42, 0x52, 0x51, 0x61, 0x52, 0x41, 0x51, 0x41, 0x53, 0x62, 0x51, 0x41, 0x44, 0x62, 0x51, 0x41, 0x44, 0x62,

19、0x52, 0x62, 0x42, 0x61, 0x92, 0x81, 0x84, 0x02, 0x61, 0x81, 0x92, 0x92, 0xb2, 0x81, 0x91, 0x82, 0x01, 0x81, 0x61, 0x51, 0x41, 0x54, 0x51, 0x41, 0x51, 0x61, 0x54, 0x62, 0x62, 0x54, 0x02, 0x42, 0x44, 0x44, 0x00;const char code c_music4=0x04, 0x02, 0x41, 0x51, 0x62, 0x61, 0x61, 0x62, 0x52, /*夢(mèng)醒時(shí)分*/ 0x6

20、2, 0x81, 0x61, 0x62, 0x61, 0x81, 0x92, 0x92, 0x92, 0xa2, 0x82, 0x62, 0x62, 0x62, 0x61, 0x51, 0x42, 0x41, 0x41, 0x42, 0x22, 0x62, 0x81, 0x41, 0x44, 0x51, 0x52, 0x01, 0x52, 0x42, 0x81, 0x61, 0x52, 0x52, 0x41, 0x51, 0x62, 0x61, 0x61, 0x62, 0x52, 0x62, 0x81, 0x61, 0x62, 0x61, 0x81, 0x92, 0x91, 0x91, 0x9

21、2, 0xa2, 0x82, 0x62, 0x61, 0x81, 0x81, 0x81, 0x92, 0xb2, 0xb2, 0x92, 0x72, 0x52, 0x52, 0x81, 0x81, 0x92, 0xb2, 0xb2, 0x92, 0xb2, 0xc2, 0xc4, 0xc4, 0x01, 0x81, 0x81, 0x81, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xc1, 0xc1, 0xc2, 0xb1, 0xa1, 0xb2, 0xb2, 0xb2, 0xc2, 0x62, 0x82, 0x82, 0x81, 0x81, 0x92, 0xb1, 0xb

22、1, 0xb2, 0xb2, 0xc2, 0x91, 0xb1, 0xb2, 0xb1, 0xb1, 0xc2, 0xc1, 0xc1, 0xc2, 0xb2, 0xd2, 0xc1, 0x81, 0x81, 0x81, 0x81, 0x81, 0xd2, 0xd2, 0xd2, 0xf2, 0xd2, 0xc1, 0xc1, 0xc2, 0xb1, 0xa1, 0xb2, 0xb2, 0xb2, 0xc2, 0x62, 0x82, 0x82, 0x81, 0x81, 0x92, 0xb1, 0xb1, 0xb2, 0xb1, 0xb1, 0xc2, 0x91, 0xb1, 0xb2, 0xb

23、1, 0xb1, 0xc2, 0xc1, 0xc1, 0xc2, 0xb2, 0xd4, 0xc2, 0x01, 0xb1, 0xb4, 0xb4, 0xb4, 0xb4, 0x00;const char code c_music5=0x54, 0x64, 0x64, /*大長(zhǎng)今*/ 0x64, 0x02, 0x52, 0x44, 0x24, 0x44, 0x44, 0x51, 0x43, 0x44, 0x44, 0x54, 0x64, 0x64, 0x64, 0x02, 0x82, 0x64, 0x64, 0x54, 0x64, 0x64, 0x64, 0x64, 0x84, 0x94, 0

24、x94, 0x94, 0x84, 0x64, 0x64, 0x84, 0x94, 0x81, 0x91, 0x82, 0x84, 0x84, 0x54, 0x64, 0x64, 0x54, 0x02, 0x62, 0x64, 0x54, 0x64, 0x24, 0x41, 0x23, 0x94, 0x94, 0x24, 0x24, 0x24, 0x54, 0x64, 0x64, 0x64, 0x02, 0x52, 0x44, 0x24, 0x44, 0x44, 0x51, 0x43, 0x44, 0x44, 0x54, 0x64, 0x64, 0x64, 0x02, 0x82, 0x64, 0

25、x64, 0x54, 0x64, 0x64, 0x64, 0x64, 0x84, 0x94, 0x94, 0x94, 0x02, 0x82, 0x64, 0x64, 0x84, 0x94, 0x84, 0x84, 0x84, 0x54, 0x64, 0x64, 0x54, 0x02, 0x62, 0x64, 0x54, 0x64, 0x24, 0x41, 0x23, 0x24, 0x24, 0x24, 0x24, 0x24, 0x54, 0x02, 0x42, 0x24, 0x54, 0x02, 0x42, 0x24, 0x54, 0x64, 0x44, 0x54, 0x02, 0x62, 0

26、x84, 0x94, 0x02, 0x82, 0x64, 0x54, 0x02, 0x42, 0x24, 0x24, 0x14, 0x24, 0x41, 0x23, 0x24, 0x24, 0x24, 0x24, 0x24, 0x14, 0x14, 0x14, 0x14, 0x02, 0x22, 0x42, 0x52, 0x62, 0x52, 0x44, 0x02, 0x22, 0x44, 0x44, 0x54, 0x64, 0x64, 0x64, 0x64, 0x64, 0x84, 0x94, 0x02, 0xb2, 0x94, 0x84, 0x84, 0x84, 0x84, 0x61, 0

27、x81, 0x92, 0x04, 0x92, 0x82, 0x64, 0x02, 0x52, 0x64, 0x02, 0x52, 0x62, 0x52, 0x44, 0x44, 0x44, 0x41, 0x23, 0x24, 0x44, 0x54, 0x54, 0x54, 0x54, 0x64, 0x64, 0x44, 0x41, 0x23, 0x24, 0x24, 0x24, 0x24, 0x00;const char code c_music6=0x24, 0x42, 0x52, 0x64, 0x62, 0x92, /*漫步人生路*/ 0x84, 0x62, 0x52, 0x64, 0x0

28、2, 0x62, 0x72, 0x62, 0x62, 0x52, 0x52, 0x42, 0x41, 0x31, 0x22, 0x44, 0x02, 0x52, 0x34, 0x34, 0x24, 0x42, 0x52, 0x64, 0x62, 0x92, 0xa4, 0x82, 0x62, 0x64, 0x02, 0x62, 0x72, 0x62, 0x52, 0x42, 0x32, 0x42, 0x52, 0x62, 0x42, 0x32, 0x22, 0x12, 0x24, 0x24, 0x42, 0x32, 0x42, 0x52, 0x64, 0x52, 0x62,0x74, 0x74

29、, 0x72, 0x81, 0x71, 0x62, 0x52, 0x64, 0x74, 0x84, 0x02, 0x62, 0x94, 0x92, 0x82, 0x94, 0x92, 0xb2, 0x92, 0x82, 0x82, 0x92, 0x64, 0x52, 0x42, 0x54, 0x52, 0x42, 0x54, 0x42, 0x42, 0x82, 0x62, 0x62, 0x52, 0x42, 0x34, 0x62, 0x62, 0x94, 0x92, 0x82, 0x94, 0x92, 0xb2, 0x92, 0x82, 0x82, 0x92, 0x64, 0x52, 0x42

30、, 0x54, 0x42, 0x82, 0x64, 0x52, 0x42, 0x52, 0x61, 0x51, 0x42, 0x32, 0x24, 0x24, 0x00;const char code c_music7=0x02, 0x12, 0x12, 0x22, /*最浪漫的事*/ 0x44, 0x42, 0x42, 0x42, 0x22, 0x22, 0x62, 0x64, 0x64, 0x02, 0x12, 0x24, 0x42, 0x42, 0x42, 0x42, 0x44, 0x62, 0x82, 0x84, 0x84, 0x84, 0x02, 0x82, 0x92, 0x82, 0x92, 0x82, 0x94, 0x82, 0x51, 0x61, 0x62, 0x51, 0x41, 0x44, 0x02, 0x42, 0x42, 0x22, 0x44, 0x42, 0x22, 0x42, 0x64, 0x52, 0x5

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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)論