課程設(shè)計(jì)名稱:數(shù)字音樂盒
實(shí)驗(yàn)報(bào)告 課程設(shè)計(jì)名稱:數(shù)字音樂盒 課程設(shè)計(jì)單位:自動(dòng)化031班 課設(shè)小組成員:杜斐斐 王薄 單片機(jī)課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告 課程設(shè)計(jì)題目:數(shù)字音樂盒 課程設(shè)計(jì)要求:1.利用I/O口產(chǎn)生一定頻率的方波,驅(qū)動(dòng)蜂鳴器,發(fā)出不同的音調(diào),從而演奏樂曲(最少三首樂曲,每首不少于30秒) 2.采用LCD顯示信息 3.開機(jī)時(shí)有英文歡迎提示字符,播放時(shí)顯示歌曲序號(hào)(或名稱) 4.可通過功能鍵選擇樂曲,暫停,播放。 5.選作內(nèi)容:顯示樂曲播放時(shí)間或剩余時(shí)間 硬件電路:本設(shè)計(jì)中用到了98C51單片機(jī),4*4鍵盤,蜂鳴器,16*2 LCD,七段 顯示數(shù)碼管LED。(硬件電路原理圖附于后頁) 原理說明:當(dāng)鍵盤有鍵按下時(shí),判斷鍵值,啟動(dòng)計(jì)數(shù)器T0,產(chǎn)生一定頻率的脈沖,驅(qū)動(dòng)蜂鳴器,放出樂曲。同時(shí)啟動(dòng)定時(shí)器T1,顯示樂曲播放的時(shí)間,并驅(qū)動(dòng)LCD,顯示歌曲號(hào)及播放時(shí)間。也可在LED顯示歌曲號(hào)。 (1) 硬件電路中用P1.0~P1.7控制按鍵,其中P1.0~P1.3掃描行,P1.4~P1.7掃描列。 (2) 用P0.0~P0.7,P2.0~P2.7控制LED,其中P0.0~P0.7控制七段碼a,b,c,d,e,f,g,用P2.0~P2.7為數(shù)碼管位選信號(hào)。 (3) 用,P2.0~P2.2作為L(zhǎng)CD的RS,R/W,E的控制信號(hào)。用P0.0~P0.7作為L(zhǎng)CD的D0~D7的控制信號(hào)。 (4) 用P3.7口控制蜂鳴器(J2,J4斷開,J3短接)。 (5) 電路為12MHZ晶振頻率工作,起振電路中C1,C2均為30pf。 軟件設(shè)計(jì):本程序可以實(shí)現(xiàn)課程設(shè)計(jì)的基本要求和附加功能,并可以通過按鍵播放七首歌曲。實(shí)驗(yàn)程序如下:
;-------------------------------------------------------------------- ;第八首歌《彩云追月》 ;-------------------------------------------------------------------- TABLE80: DB 86H,92H,12H,22H,32H,52H,68H,63H,52H,34H,62H,0B2H,0B2H,62H,51H,61H,51H,31H,54H DB 62H,0B2H,0B2H,62H,52H,32H,52H,52H,51H,61H,51H,31H,34H,52H,62H,74H,32H,52H,52H,32H, DB 21H,31H,21H,11H,24H DB 32H,52H,52H,32H,22H,12H,24H,32H,52H,52H,32H,62H,52H,61H,51H, DB 31H,21H,21H,31H,21H,11H,1CH DB 21H,31H,22H,23H,31H,21H,18H,02H,0B2H,0BCH,0B4H,72H,61H,51H,72H,61H, DB 71H,61H,51H,61H,71H,61H,6FH DB 86H,94H,12H,22H,32H,52H,64H,62H,51H,31H,52H,21H,31H,21H,33H,62H,0B2H,0B2H,62H, DB 51H,61H,51H,31H,54H DB 62H,0B2H,72H,61H,51H,51H,61H,51H,31H,54H,61H,0B2H,72H,61H,51H,51H,61H,51H,31H,32H, DB 21H,11H,32H,51H,61H,54H DB 02H,32H,24H,32H,52H,52H,32H,22H,31H,21H,11H,24H,32H,52H,62H,0B2H,72H,61H,51H,61H, DB 51H,31H,32H,52H,52H,32H,62H DB 51H,31H,31H,21H,11H,91H,23H,31H,21H,1CH,12H,24H,32H,62H,51H,31H,34H,0B4H,72H, DB 61H,51H,63H,71H,64H DB 0B2H,54H,72H,62H,71H,61H,54H,61H,51H,31H,21H,34H,73H,61H,54H,22H,32H,52H,22H,36H, DB 52H,62H,61H,31H,32H,21H,11H,21H,11H,91H,81H DB 94H,52H,62H,52H,42H,32H,22H,32H,52H,0B4H,74H,64H,52H,61H,51H,41H,5CH,02H,52H,0B4H,74H, DB 63H,51H,61H,51H,31H,21H DB 00
;-------------------------------------------------------------------- ;第九首<<十年>> ;-------------------------------------------------------------------- TABLE90: DB 02H,11H,21H,32H,32H,22H,32H,21H,11H,0A1H,91H,92H,0D1H,91H,83H,91H,0A2H,91H, DB 81H,94H,11H,0A1H,91H,0A1H,98H,03H,81H,0A1H,0A1H,91H,0A1H DB 98H,04H,02H,11H,21H,32H,32H,22H,32H,21H,31H,51H,11H,13H,31H,22H,22H,21H,11H,0A1H, DB 11H,13H,11H,11H,0A1H,91H,0A1H DB 11H,93H,94H,03H,81H,11H,0A1H,91H,81H,92H,0A1H,91H,94H,08H,03H,81H,32H,21H,11H,22H, DB 31H,21H,21H,83H DB 01H,11H,91H,0A1H,11H,61H,51H,11H,34H,01H,31H,21H,31H,48H,23H,31H,32H,42H,38H,03H, DB 11H,21H,52H,31H DB 33H,31H,31H,41H,51H,61H,23H,21H,21H,41H,31H,21H,13H,0D1H,0D1H,21H,11H,0A1H,11H,91H, DB 92H,91H,11H,0A1H,91H DB 0A1H,31H,31H,22H,0A1H,11H,14H,01H,11H,21H,31H,63H,31H,42H,51H,31H,31H,22H,11H,21H,52H, DB 31H,33H,31H,31H,41H DB 51H,61H,23H,21H,21H,41H,31H,21H,13H,0D1H,0D1H,21H,11H,0A1H,11H,91H,92H,91H, DB 11H,0A1H,91H DB 0A2H,41H,31H,22H,31H,21H,12H,12H,11H,11H,21H,31H,63H,51H,32H,11H,21H,26H,11H, DB 0A1H,18H DB 00
;-------------------------------------------------------------------- ;第十首<<你的愛給了誰>> ;-------------------------------------------------------------------- TABLE100: DB 02H,91H,0A1H,16H,21H,11H,0A6H,81H,0A1H,9CH,02H,91H,0A1H,16H,21H,31H,24H,21H, DB 0A1H,11H,0A1H DB 9CH,02H,11H,21H,36H,32H,24H,21H,0A1H,11H,0A1H,9CH,02H,91H,0A1H,14H,11H,11H,21H,11H,0A4H, DB 04H,04H,02H,0A1H,11H,0A1H,93H,92H DB 02H,61H,71H,0B4H,0B2H,0B1H,0B1H,76H,0B1H,71H,6CH,02H,61H,71H,0B6H,0B1H,0B1H,76H,0B1H, DB 71H,6CH,02H,51H,61H,56H,61H,51H,54H,51H,0B1H,71H,0B1H DB 72H,62H,68H,02H,61H,51H,66H,62H,58H,0CH,02H,51H,41H,5FH DB 02H,91H,0A1H,16H,21H,11H,0A6H,81H,0A1H,9CH,02H,91H,0A1H,16H,21H,31H,24H,21H, DB 0A1H,11H,0A1H DB 9CH,02H,11H,21H,36H,32H,24H,21H,0A1H,11H,0A1H,9CH,02H,91H,0A1H,14H,11H,11H,21H, DB 11H,0A4H,04H,04H,02H,0A1H,11H,0A1H,93H,92H DB 02H,61H,71H,0B4H,0B2H,0B1H,0B1H,76H,0B1H,71H,6CH,02H,61H,71H,0B6H,0B1H,0B1H,76H, DB 0B1H,71H,6CH,02H,51H,61H,56H,61H,51H,54H,51H,0B1H,71H,0B1H DB 66H,62H,54H,0B2H,71H,61H,6CH DB 00
END 實(shí)驗(yàn)控制流程圖如下:
使用說明:鍵盤如下: 0 1 2 3 4 5 6 7 8 9 A B C D E F 按鍵功能說明: 1~A:十首歌曲 C:上一首歌曲 D:下一首歌曲 E:歌曲暫停 F:開機(jī)畫面 程序調(diào)試中出現(xiàn)的問題及解決的辦法: 1. 有時(shí)會(huì)出現(xiàn)程序一點(diǎn)錯(cuò)誤也沒有,但就是不能正常運(yùn)行的現(xiàn)象,最后我們發(fā)行是因?yàn)槌绦蛑杏械闹噶顣鴮懙貌灰?guī)范導(dǎo)致的,例如有的RET返回指令一定要按正確格式書寫或在兩行指令間最好不要留空行。 2. 程序中的跳轉(zhuǎn)指令的運(yùn)用很重要,為保險(xiǎn)起見,都用LJMP,我們就遇到過跳轉(zhuǎn)指令用錯(cuò)程序無法正常運(yùn)行的現(xiàn)象。當(dāng)用JNZ指令時(shí),跳轉(zhuǎn)范圍比較少,這時(shí)要用一個(gè)標(biāo)號(hào)中轉(zhuǎn)。 3. 編程時(shí)要注意,在程序開始時(shí),要寫入各定時(shí)器中斷的入口地址。 4. 編程過程中要注意加注釋或分割線,否則,在程序過長(zhǎng)時(shí)容易變得很亂,不便于查找或更改。 5. 程序的結(jié)構(gòu)要設(shè)計(jì)的合理,避免上下亂調(diào)用的現(xiàn)象,這樣會(huì)使程序更加清晰化。 6. 編程前要加流程圖,這樣會(huì)使思路清晰,例如數(shù)字音樂盒的設(shè)計(jì)思路完全可以按著MP3的工作方式列寫流程圖。 7. LCD計(jì)時(shí)正常顯示的解決辦法: a. 兩個(gè)定時(shí)器同時(shí)工作,存在中斷時(shí)序問題,剛開始時(shí)我們把定時(shí)器1設(shè)定在方式3,計(jì)250us,由于定時(shí)中斷過于頻繁,使CPU負(fù)載過大,導(dǎo)致音樂不能正常播放,時(shí)間不能正常顯示。解決辦法:將定時(shí)器1設(shè)定在工作方式1,16位計(jì)數(shù),計(jì)50ms,效果有很大改觀。但還有問題。 b. 當(dāng)音樂為全4拍起始時(shí),此時(shí)音樂節(jié)奏與定時(shí)器T1中斷頻率錯(cuò)開,LCD顯示和音樂播放都會(huì)好一些。 c. 另外,在歌曲中,當(dāng)遇到一個(gè)音符發(fā)音為4拍,在編曲中為*CH,托因時(shí)間較長(zhǎng),當(dāng)定時(shí)器T1此時(shí)來中斷時(shí),就會(huì)對(duì)歌曲播放產(chǎn)生影響,若改為發(fā)音一拍,中斷對(duì)歌曲播放影響減弱,但音樂效果變差。 d. 改進(jìn)方案:若采用可以定時(shí)時(shí)間更長(zhǎng)的單片機(jī),可以避免所有問題。 收獲,體會(huì)與建議: 1. 本學(xué)期學(xué)習(xí)單片機(jī)的時(shí)間只有8周時(shí)間,對(duì)單片機(jī)的硬件設(shè)計(jì),軟件設(shè)計(jì)掌握的深度不夠,但通過此次課程設(shè)計(jì),卻改變了很多,首先對(duì)于硬件電路的工作原理有了進(jìn)一步的學(xué)習(xí),同樣就有了進(jìn)一步的認(rèn)識(shí);其次軟件方面,在程序的設(shè)計(jì),程序的調(diào)試方面都學(xué)到了很多東西,這是第一次編寫單片機(jī)的大程序,很有成就感。 2. 在一個(gè)好的氛圍里才能踏下心來做東西,在這幾天課設(shè)的時(shí)間里,實(shí)驗(yàn)室的氛圍對(duì)我們的影響很大,大家一起努力,這也是我們能完成課設(shè)的動(dòng)力。另外在編程中出現(xiàn)問題時(shí),一定要戒驕戒躁,腳踏實(shí)地,認(rèn)真看書,仔細(xì)分析,仔細(xì)調(diào)試,就一定會(huì)發(fā)現(xiàn)錯(cuò)誤,克服困難,我們也是這么做的,這在課設(shè)中十分重要。 3. 最后要提一點(diǎn)建議,希望下一次課程設(shè)計(jì)中,每個(gè)人都能有一塊實(shí)驗(yàn)開發(fā)板,這樣能使每個(gè)人都能得到充分的鍛煉!
|
|