发表于:2009/10/1 17:22:40
#0楼
用单片机实现的音乐播放器图和程序
图1 乐曲播放器电路图源程序清单[/b] [/b] ;**************************************; ; mcu音乐播放器 ; ;作者:耶涛 ; ;开发时间:2005年9月20日 ; ;**************************************; org 0000h ajmp start org 000bh ajmp tim0 org 001bh reti org 0023hstart: mov r5,#00h ;初始化 mov tmod,#00010001b mov ie,#10101010b mov dptr,#tab2 ;装第一首歌 mov 30h,dpl ;dptr低8位送30h暂存 mov 31h,dph ;dptr高8位送31h暂存start1: inc r7 ;产生8位随机数 mov a,#12h mov b,r7 mul ab mov p1,a ;8位随机数由p1口输出 mov dpl,30h mov dph,31h mov a,#00h movc a,@a+dptr ;查表 mov r0,a ;音符数据送r0崭存 mov a,#00h inc dptr movc a,@a+dptr ;查表 mov r1,a ;节拍数据送r1崭存 inc dptr mov 30h,dpl mov 31h,dph cjne a,#01h,elect ;一首歌没结束转elect inc r5 ;结束歌曲计数器加1 elect: jz start ;所有歌曲结束转start循环 mov a,r0 jnz sing clr tr0 setb p3.7 loop1: acall delay ;调用延时子程序 djnz r1,loop1 sjmp start1 sing: mov dptr,#tab1 ;音符表首址送dptr dec r0 ;计算音符 mov a,r0 mov b,#02h mul ab mov r0,a movc a,@a+dptr ;查表 mov 21h,a inc dptr mov a,r0 movc a,@a+dptr mov 20h,a mov tl0,20h mov th0,21h setb tr0 ;开t0定时器 loop2: acall delay djnz r1,loop2 ajmp start1 tim0: mov tl0,20h mov th0,21h cpl p3.7 reti ;中断返回 delay: mov r2,#70 delay1: mov r3,#252 djnz r3,$ jnb p3.4,form ;上一曲开关按下转form jnb p3.5,next ;下一曲开关按下转next djnz r2,delay1 ret form: clr ea ;关中断 jnb p3.4,$ ;等待键释放 cjne r5,#00h,zero ;不是第一首歌曲转zer0 mov r5,#08h ;是第一首将最后一首歌曲装入歌曲计数器 sjmp keywork zero: dec r5 ;歌曲向上进一首 sjmp keywork next: clr ea jnb p3.5,$ inc r5 ;歌曲下翻一首keywork: mov dptr,#tab ;将歌曲排列表装入dptr mov a,r5 ;将r5的内容送a rl a setb ea ;开中断 jmp @a+dptr ;根据a的内容转向不同歌曲 tab: ajmp music2 ajmp music3 ajmp music4 ajmp music5 music2: mov dptr,#tab2 ;第2首歌曲首址送dptr gong: mov 30h,dpl mov 31h,dph ajmp start1 music3: mov dptr,#tab3 sjmp gong music4: mov dptr,#tab4 sjmp gong music5: mov dptr,#tab5 sjmp gong ;********************(音符表)**********************; tab1: dw 64021,64185,64331,64400,64524,64632,64732, dw 64777,64860,64934,64968,65030,65085,65134, dw 65157,65198,65235,65252,65283,65310,65335,;*********************(兰花草)***********************;tab2: dw 0608h,0a08h,0a08h,0a08h,0a18h,0908h,0808h,0908h, dw 0808h,0708h,0620h,0d08h,0d08h,0d08h,0d08h,0d18h, dw 0c08h,0a08h,0c08h,0c08h,0b08h,0a20h,0a08h,0d08h, dw 0d08h,0c08h,0a18h,0908h,0808h,0908h,0808h,0708h, dw 0610h,0310h,0308h,0808h,0808h,0708h,0618h,0a08h, dw 0908h,0808h,0708h,0508h,0620h,0908h,0808h,0708h, dw 0508h,0640h,0001h;**********************(梁祝)*************************; tab3: dw 0a10h,0c08h,0d04h,0f08h,1004h,0d04h,0f04h,0c08h, dw 1308h,1504h,1404h,1304h,1104h,1304h,1018h,1008h, dw 1004h,1104h,0e08h,0d04h,0c08h,0d04h,0f08h,1008h, dw 0a08h,0f08h,0d04h,0c04h,0d04h,0f04h,0c18h,1108h, dw 1304h,0e08h,1008h,0d04h,0f04h,0c08h,0c10h,0a08h, dw 0c02h,0a08h,0c08h,0d02h,0e04h,1004h,0d18h,0c04h, dw 0d04h,0f08h,1004h,1308h,1108h,1008h,1104h,1004h, dw 0f08h,0d04h,0c04h,0a10h,0f10h,0d08h,0f02h,0d04h, dw 0c04h,0a04h,0c04h,0d04h,0f04h,0c38h,0001h;*****************(让我们荡起双桨)*********************;tab4: dw 0608h,0808h,0908h,0a18h,0c08h,0a08h,0808h,0910h, dw 0620h,0008h,0808h,0908h,0a08h,0c18h,0001h,0c08h, dw 0d10h,0910h,0a30h,0001h,0a08h,0c08h,0d20h,0c18h, dw 0d08h,0f08h,0e04h,0d04h,0c08h,0d08h,0a10h,0004h, dw 0808h,0908h,0a18h,0c08h,0810h,0610h,0808h,0908h, dw 0a08h,0d08h,0c30h,0010h,0a20h,0d18h,0001h,0d08h, dw 0c08h,0b08h,0a10h,0001h,0920h,0a18h,0c08h,0608h, dw 0808h,0910h,0010h,0808h,0908h,0a10h,0c0bh,0001h, dw 0c04h,0d10h,0f10h,0e08h,0d08h,0c08h,0a08h,0d40h, dw 0001h;*********************(童年)****************************;tab5: dw 0a08h,0c08h,0c10h,0c08h,0a08h,0d08h,0d08h,0e08h, dw 0d08h,0d08h,0d08h,0d08h,0c08h,0f10h,0f08h,0f08h, dw 0f08h,0d08h,0f08h,0d08h,0c40h,0a08h,0c08h,0c10h, dw 0c08h,0a08h,0d08h,0d08h,0e08h,0d08h,0d08h,0d08h, dw 0d08h,0c08h,0f10h,0f08h,0f08h,0f08h,0d08h,0d08h, dw 0f08h,1040h,1308h,1308h,1310h,1310h,1108h,1008h, dw 0f08h,0f10h,0d08h,0d08h,0f08h,0d08h,0f08h,1008h, dw 1008h,1008h,1008h,1008h,0f08h,1108h,1008h,1040h, dw 1108h,1110h,1108h,1108h,1008h,1010h,0f08h,0f10h, dw 0f08h,1008h,0f08h,0d08h,0c08h,0c08h,0c10h,0c08h, dw 0d08h,0c08h,1008h,1108h,0f40h,0001h,0000h end
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=102206&Name=zhy058
图1 乐曲播放器电路图源程序清单[/b] [/b] ;**************************************; ; mcu音乐播放器 ; ;作者:耶涛 ; ;开发时间:2005年9月20日 ; ;**************************************; org 0000h ajmp start org 000bh ajmp tim0 org 001bh reti org 0023hstart: mov r5,#00h ;初始化 mov tmod,#00010001b mov ie,#10101010b mov dptr,#tab2 ;装第一首歌 mov 30h,dpl ;dptr低8位送30h暂存 mov 31h,dph ;dptr高8位送31h暂存start1: inc r7 ;产生8位随机数 mov a,#12h mov b,r7 mul ab mov p1,a ;8位随机数由p1口输出 mov dpl,30h mov dph,31h mov a,#00h movc a,@a+dptr ;查表 mov r0,a ;音符数据送r0崭存 mov a,#00h inc dptr movc a,@a+dptr ;查表 mov r1,a ;节拍数据送r1崭存 inc dptr mov 30h,dpl mov 31h,dph cjne a,#01h,elect ;一首歌没结束转elect inc r5 ;结束歌曲计数器加1 elect: jz start ;所有歌曲结束转start循环 mov a,r0 jnz sing clr tr0 setb p3.7 loop1: acall delay ;调用延时子程序 djnz r1,loop1 sjmp start1 sing: mov dptr,#tab1 ;音符表首址送dptr dec r0 ;计算音符 mov a,r0 mov b,#02h mul ab mov r0,a movc a,@a+dptr ;查表 mov 21h,a inc dptr mov a,r0 movc a,@a+dptr mov 20h,a mov tl0,20h mov th0,21h setb tr0 ;开t0定时器 loop2: acall delay djnz r1,loop2 ajmp start1 tim0: mov tl0,20h mov th0,21h cpl p3.7 reti ;中断返回 delay: mov r2,#70 delay1: mov r3,#252 djnz r3,$ jnb p3.4,form ;上一曲开关按下转form jnb p3.5,next ;下一曲开关按下转next djnz r2,delay1 ret form: clr ea ;关中断 jnb p3.4,$ ;等待键释放 cjne r5,#00h,zero ;不是第一首歌曲转zer0 mov r5,#08h ;是第一首将最后一首歌曲装入歌曲计数器 sjmp keywork zero: dec r5 ;歌曲向上进一首 sjmp keywork next: clr ea jnb p3.5,$ inc r5 ;歌曲下翻一首keywork: mov dptr,#tab ;将歌曲排列表装入dptr mov a,r5 ;将r5的内容送a rl a setb ea ;开中断 jmp @a+dptr ;根据a的内容转向不同歌曲 tab: ajmp music2 ajmp music3 ajmp music4 ajmp music5 music2: mov dptr,#tab2 ;第2首歌曲首址送dptr gong: mov 30h,dpl mov 31h,dph ajmp start1 music3: mov dptr,#tab3 sjmp gong music4: mov dptr,#tab4 sjmp gong music5: mov dptr,#tab5 sjmp gong ;********************(音符表)**********************; tab1: dw 64021,64185,64331,64400,64524,64632,64732, dw 64777,64860,64934,64968,65030,65085,65134, dw 65157,65198,65235,65252,65283,65310,65335,;*********************(兰花草)***********************;tab2: dw 0608h,0a08h,0a08h,0a08h,0a18h,0908h,0808h,0908h, dw 0808h,0708h,0620h,0d08h,0d08h,0d08h,0d08h,0d18h, dw 0c08h,0a08h,0c08h,0c08h,0b08h,0a20h,0a08h,0d08h, dw 0d08h,0c08h,0a18h,0908h,0808h,0908h,0808h,0708h, dw 0610h,0310h,0308h,0808h,0808h,0708h,0618h,0a08h, dw 0908h,0808h,0708h,0508h,0620h,0908h,0808h,0708h, dw 0508h,0640h,0001h;**********************(梁祝)*************************; tab3: dw 0a10h,0c08h,0d04h,0f08h,1004h,0d04h,0f04h,0c08h, dw 1308h,1504h,1404h,1304h,1104h,1304h,1018h,1008h, dw 1004h,1104h,0e08h,0d04h,0c08h,0d04h,0f08h,1008h, dw 0a08h,0f08h,0d04h,0c04h,0d04h,0f04h,0c18h,1108h, dw 1304h,0e08h,1008h,0d04h,0f04h,0c08h,0c10h,0a08h, dw 0c02h,0a08h,0c08h,0d02h,0e04h,1004h,0d18h,0c04h, dw 0d04h,0f08h,1004h,1308h,1108h,1008h,1104h,1004h, dw 0f08h,0d04h,0c04h,0a10h,0f10h,0d08h,0f02h,0d04h, dw 0c04h,0a04h,0c04h,0d04h,0f04h,0c38h,0001h;*****************(让我们荡起双桨)*********************;tab4: dw 0608h,0808h,0908h,0a18h,0c08h,0a08h,0808h,0910h, dw 0620h,0008h,0808h,0908h,0a08h,0c18h,0001h,0c08h, dw 0d10h,0910h,0a30h,0001h,0a08h,0c08h,0d20h,0c18h, dw 0d08h,0f08h,0e04h,0d04h,0c08h,0d08h,0a10h,0004h, dw 0808h,0908h,0a18h,0c08h,0810h,0610h,0808h,0908h, dw 0a08h,0d08h,0c30h,0010h,0a20h,0d18h,0001h,0d08h, dw 0c08h,0b08h,0a10h,0001h,0920h,0a18h,0c08h,0608h, dw 0808h,0910h,0010h,0808h,0908h,0a10h,0c0bh,0001h, dw 0c04h,0d10h,0f10h,0e08h,0d08h,0c08h,0a08h,0d40h, dw 0001h;*********************(童年)****************************;tab5: dw 0a08h,0c08h,0c10h,0c08h,0a08h,0d08h,0d08h,0e08h, dw 0d08h,0d08h,0d08h,0d08h,0c08h,0f10h,0f08h,0f08h, dw 0f08h,0d08h,0f08h,0d08h,0c40h,0a08h,0c08h,0c10h, dw 0c08h,0a08h,0d08h,0d08h,0e08h,0d08h,0d08h,0d08h, dw 0d08h,0c08h,0f10h,0f08h,0f08h,0f08h,0d08h,0d08h, dw 0f08h,1040h,1308h,1308h,1310h,1310h,1108h,1008h, dw 0f08h,0f10h,0d08h,0d08h,0f08h,0d08h,0f08h,1008h, dw 1008h,1008h,1008h,1008h,0f08h,1108h,1008h,1040h, dw 1108h,1110h,1108h,1108h,1008h,1010h,0f08h,0f10h, dw 0f08h,1008h,0f08h,0d08h,0c08h,0c08h,0c10h,0c08h, dw 0d08h,0c08h,1008h,1108h,0f40h,0001h,0000h end
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=102206&Name=zhy058