您好,欢迎访问三七文档
OUTBITP2.3;定义音频输出端口,p2.3NEQU9;歌曲总数OUT_NUMEQUP0;数码管显视当前所放歌曲曲数ORG0000HAJMPMAINORG0003HAJMPLAST_SONG;外部中断0用于接上一曲歌按键ORG000BHAJMPF_T0;定时器0用于定时,作音符发生器用ORG0013Hq4:AJMPNEXT_SONG;外部中断1接下一曲歌按键ORG001BHAJMPSTART_PAUSE;定时器1用计数,这里用作中断,接开始/暂停键,初值为0ffH,方式2ORG0030HMAIN:MOVSP,#60HMOVDPTR,#TABLE;DPRT指向每首歌曲的入口地址的地址。MOVR0,#30H;R0中存入数据30H,这里在以30H开始的单元存放每首歌曲的入口地址,其中30H,31H存放;歌曲的节拍入口地址,32H,33H存放歌曲音符入口地址,每首歌占用四个存储存单元。MOVR5,#00H;R5中存放表TABLE中正在执行操作的序号MOVR6,#1;R6存放正在设置入口信息的歌曲数SET_TAB:MOVA,R5;设置每首歌曲的入口信息,存放在以30H开始的存储单元中。MOVCA,@A+DPTRMOV@R0,AINCR5INCR0MOVA,R5MOVCA,@A+DPTRMOV@R0,AINCR5INCR0MOVA,R5MOVCA,@A+DPTRMOV@R0,AINCR0INCR5MOVA,R5MOVCA,@A+DPTRMOV@R0,AINCR0INCR5INCR6;设置完一首歌曲后,歌曲数加一CJNER6,#N+1,SET_TAB;是否设置完,没有便继续,否则进行下面的操作;***********************************对中断,计数器的相关参数进行设置MOVTMOD,#61H;计数器0工作方式1,计数器1工作方式2MOVTH1,#0FFH;给计数器1置初值0FFH,又由于是工作方式2,所以MOVTL1,#0FFH;计数器计数为1,相当于一外部中断。SETBET1;允许计数器1中断SETBET0;允许计数器具0中断CLRPT0;计数器0为低优先级SETBPT1;计数器1为高优先级SETBIT0;外部中断0为跳沿触发SETBPX0;高优先级SETBIT1;外部中断1为跳沿触发SETBPX1;高优先级SETBEX1;允许外部中断1中断SETBEX0;允许外部中断定0中断SETBEA;开中断总开关SETBTR1;定时器1开始工作,作中断用SETBOUT;音频输出端口初始化;***********************************;设置结束CLRF0;设置F0=0,用来作暂停/播放的标置位用MOV22H,#01H;22H单元中存放正在播放的歌曲编号MOVDPTR,#OUT_TAB;将正在播放的歌曲编号送数码管显视MOVA,22HMOVCA,@A+DPTRMOVOUT_NUM,AMOVR7,#00H;R7中存放歌曲总信息的入口地址START0:MOVR4,#00H;R4存放当前正在播放歌曲的第几个节拍数MOVR0,#30H;30H开始的单元中存放歌曲的入口信息MOVA,R7;将歌曲的节拍表的入口地址送到DPTRADDA,R0MOVR0,AMOVDPH,@R0INCR0MOVDPL,@R0INCR0MOVA,R4INCR4MOVCA,@A+DPTR;取出第一节拍数,其实第一个节拍不是歌曲的第一个节拍,而是表示几分音符;****************************************************MOV26H,A;将取出的音符数+节拍数保存在职26H单元中NEXT:MOVR0,#30H;开始取出歌曲的第一个数据MOVA,R7ADDA,R0MOVR0,AMOVDPH,@R0INCR0MOVDPL,@R0INCR0MOVA,R4INCR4MOVCA,@A+DPTR;放在A中;****************************JZEND0;若为0,则表示为休止符,不唱,本次音符不唱,MOVR1,A;不为0,取出节拍数ANLA,#0FHMOVR2,AMOVA,R1SWAPAANLA,#0FHJNZSING;音符不为0,唱CLRTR0;为0,不唱,关频率发生器SJMPSING1SING:DECA;开始唱,进行相应的数据处理MOVR3,ARLAMOVDPH,@R0INCR0MOVDPL,@R0INCR0MOVCA,@A+DPTRMOV21H,AMOVTH0,AMOVA,R3RLAINCAMOVCA,@A+DPTRMOV20H,AMOVTL0,ASETBTR0;开唱SING1:LCALLDELAY;每个音符唱多久JBF0,FOR;是否暂停,AJMPNEXT;没有暂停,继续FOR:CLRTR0;暂停,不唱JBF0,$;等待播放AJMPNEXT;开始播放END0:CLRTR0;不唱MOVA,22H;唱完处理CJNEA,#N,WW;是不是全部歌曲都唱完MOV22H,#01H;全部唱完,则从第一首开始再唱MOVR7,#00HMOVOUT_NUM,#11111001B;数码管显视第一首歌曲编号AJMP没有全部唱完,唱下一首,歌曲的入口信息调整ADDA,#4MOVR7,AINC22HCLREAPUSHDPHPUSHDPLMOVA,22HMOVDPTR,#OUT_TABMOVCA,@A+DPTRMOVOUT_NUM,A;数码管显视相应的歌曲编号POPDPLPOPDPH开始下一首的演唱F_T0:MOVTH0,21H;定时器0置初值MOVTL0,20HCPLOUT;频率产生RETINEXT_SONG:PUSHACC;下一曲中断程序处理,保护现场PUSHDPHPUSHDPLCLREA;关中断MOVA,22HCJNEA,#N,Q;是最后一首吗?MOVR7,#00H;是最后一首,则R7指向第一首,演唱第一首MOV22H,#01HAJMPBACKQ:INC22H;不是最后一首,唱下一首,R7内容加4,歌曲数加1MOVA,R7ADDA,#4MOVR7,ABACK:MOVR4,#00H;数码管显视相应的歌曲编号MOVA,22HMOVDPTR,#OUT_TABMOVCA,@A+DPTRMOVOUT_NUM,A;********************************************MOVB,R0;对下首要演唱的歌曲的几分拍进行调整,同时对R0中的内容进行保护MOVR4,#00HMOVR0,#30HMOVA,R7ADDA,R0MOVR0,AMOVDPH,@R0INCR0MOVDPL,@R0INCR0MOVA,R4INCR4MOVCA,@A+DPTRMOV26H,A;结果存入26H单元中DECR4MOVR0,B;恢复R0中的内容;********************************************POPDPL;恢复现场POPDPHPOPACCSETBEARETI;中断返回LAST_SONG:PUSHACC;上一曲中断程序处理开始,保护现场PUSHDPHPUSHDPLCLREA;关中断MOVA,22H;曲目数送ACJNEA,#1,QQ;是否是第一首MOV22H,#N;是第一首歌曲MOVB,#4;将R7指向最后一首歌曲MOVA,#N-1MULABMOVR7,AAJMPBACK2;处理结束QQ:DEC22HMOVA,R7;R7减4SUBBA,#4MOVR7,ABACK2:MOVR4,#00HMOVA,22HMOVDPTR,#OUT_TABMOVCA,@A+DPTRMOVOUT_NUM,A;数码管显视相应歌曲的编号;********************************************MOVB,R0;对下首要演唱的歌曲的几分拍进行调整,同时对R0中的内容进行保护MOVR4,#00HMOVR0,#30HMOVA,R7ADDA,R0MOVR0,AMOVDPH,@R0INCR0MOVDPL,@R0INCR0MOVA,R4INCR4MOVCA,@A+DPTRMOV26H,A;结果存入26H单元中DECR4MOVR0,B;R0中的内容恢复;********************************************POPDPL;恢复现场POPDPHPOPACCSETBEARETI;中断返回START_PAUSE:CPLF0;开始/暂停中断处理程序,将标置位取反JBF0,RETURN;为1返回SETBTR0;为0则播放RETURN:RETI;中断返回DELAY:MOV27H,26H;音符演奏时间控制D2:MOV28H,#125D3:MOV29H,#248DJNZ29H,$DJNZ28H,D3DJNZ27H,D2DJNZR2,DELAYRET;OUT_TAB:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,73H;共阴数码管显视用OUT_TAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,88H,83H,0C6H,0A1H,86H,8EH,0FFH;共阳TABLE:DWSONG1,TABLE1,SONG2,TABLE2,SONG3,TABLE3,SONG4,TABLE4,SONG5,TABLE5,SONG6,TABLE6,SONG7,TABLE7,SONG8,TABLE8TABLE1:DW64580,64684,64777,64820DW64898,64968,65030,64260DW64400,64524,65058,63835,64021SONG1:;精忠报国DB66H,52H,36H,22H,12H,12H,22H,32H,98H,84H,82H,92H,14H,12H,22HDB32H,52H,22H,42H,38H,66H,52H,36H,22H,12H,22H,22H,32H,98HDB24H,22H,32H,54H,52H,32H,92H,12H,92H,82H,98H,66H,52H,36H,22HDB12H,12H,22H,32H,98H,84H,82H,92H,14H,12H,22H,32H,52H,22H,42H,38HDB66H,52H,36H,22H,12H,22H,22H,32H,98H,24H,22H,32H,54H,52H,32HDB22H,12H,92H,82H,98H,14H,24H,34H,44H,64H,0B4H,64H,32H,52HDB62H,0B2H,62H,52H,38H,24H,22H,32H,54H,52H,62H,52H,32H,32H,22H,38HDB64H,0B4H,64H,32H,52H,62H,0B2H,62H,52H,38H,22H,22H,22H,32H,52H,52HDB52H,62H,7FH,74H,04H,58H,6FHDB00TABLE2:DW64580,64684,64777,64820DW64898,64968,65030,64260DW64400,64524,65058,63835,64021SONG2:DB02H,82H;月亮代表我的心DB16H,32H,54H,02H,52HDB0A6H,32H,54H,02H,52HDB64H,74H,0B6H,64HDB52H,5CH,32H,22HDB16H,12H,14H,32H,22HDB16H,12H,14H,22H,32HDB26H,12H,94H,22H,32HDB2CHDB32H,52HDB36H,22H,14H,54HDB0ACH,92H,0A2HDB96H,0A2H,96H,82HDB3CH,54HDB36H,22H,14H,54HDB0ACH,92H,0A2HDB16H,12H,14H,22H,32HDB2C
本文标题:音乐盒汇编程序
链接地址:https://www.777doc.com/doc-4328071 .html