您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 国内外标准规范 > 51单片机汇编语言音乐程序
01两只老虎NEXTBIT10H;定义标志位ORG0000HJMPMAINORG000BHJMPTONEORG001BHJMPBEATORG0100HMAIN:MOVTMOD,#11HMOVTH0,R2MOVTL0,R3MOVTH1,#3CHMOVTL1,#0B0HMOVR4,#00HMOVDPTR,#TABYD:MOVA,R4;取音调数据MOVCA,@A+DPTRMOVR2,AXRLA,#00HJNZJP;直接取节拍INCR4CALLPD;判断指针是否溢出MOVA,R4MOVCA,@A+DPTRMOVR3,AXRLA,#0FFHJZJPMOVA,R2XRLA,#0FFHJNZMAINJP:INCR4;取节拍数据CALLPDMOVA,R4MOVCA,@A+DPTRMOVR5,ASETBEASETBET0SETBET1SETBTR0SETBTR1SETBNEXTJBNEXT,$INCR4CALLPDJMPYDPD:MOVA,R4CJNEA,#00H,L1INCDPHL1:RET;音调产生子程序TONE:CPLP2.0MOVTH0,R2MOVTL0,R3RETI;节拍产生子程序BEAT:DJNZR5,L2MOVTH1,#3CHMOVTL1,#0B0HL3:RETIL2:CLRTR0CLRTR1CLRNEXTJMPL3;两只老虎音符表TAB:DB0FBH,0F9H,08H,0FCH,066H,08H,0FCH,0C7H,08H,0FBH,0F9H,08HDB0FBH,0F9H,08H,0FCH,066H,08H,0FCH,0C7H,08H,0FBH,0F9H,08HDB0FCH,0C7H,08H,0FCH,0F3H,08H,0FDH,4AH,10H,0FCH,0C7H,08HDB0FCH,0F3H,08H,0FDH,4AH,08H,0FDH,4AH,04H,0FDH,95H,04HDB0FDH,4AH,04H,0FCH,0F3H,04H,0FCH,0C7H,08H,0FBH,0F9H,08HDB0FDH,4AH,04H,0FDH,95H,04H,0FDH,4AH,04H,0FCH,0F3H,04HDB0FCH,0C7H,08H,0FBH,0F9H,08H,0FCH,66H,08H,0FAH,93H,08HDB0FBH,0F9H,08H,00H,08H,0FCH,66H,04H,0FAH,93H,08HDB0FBH,0F9H,08H,00H,10H,0FFH,0FFHEND02祝你平安ORG0000HLJMPSTARTORG000BHINC20H;中断服务,中断计数器加1MOVTH0,#0D8HMOVTL0,#0EFH;12M晶振,形成10毫秒中断RETISTART:MOVSP,#50HMOVTH0,#0D8HMOVTL0,#0EFHMOVTMOD,#01HMOVIE,#82HMUSIC0:NOPMOVDPTR,#DAT;表头地址送DPTRMOV20H,#00H;中断计数器清0MOVB,#00H;表序号清0MUSIC1:NOPCLRAMOVCA,@A+DPTR;查表取代码JZEND0;是00H,则结束CJNEA,#0FFH,MUSIC5LJMPMUSIC3MUSIC5:NOPMOVR6,AINCDPTRMOVA,BMOVCA,@A+DPTR;取节拍代码送R7MOVR7,ASETBTR0;启动计数MUSIC2:NOPCPLP3.3MOVA,R6MOVR3,ALCALLDELMOVA,R7CJNEA,20H,MUSIC2;中断计数器(20H)=R7否?;不等,则继续循环MOV20H,#00H;等于,则取下一代码INCDPTR;INCBLJMPMUSIC1MUSIC3:NOPCLRTR0;休止100毫秒MOVR2,#0DHMUSIC4:NOPMOVR3,#0FFHLCALLDELDJNZR2,MUSIC4INCDPTRLJMPMUSIC1END0:NOPMOVR2,#64H;歌曲结束,延时1秒后继续MUSIC6:MOVR3,#00HLCALLDELDJNZR2,MUSIC6LJMPMUSIC0DEL:NOPDEL3:MOVR4,#02HDEL4:NOPDJNZR4,DEL4NOPDJNZR3,DEL3RETNOPDAT:db26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20hdb30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20hdb20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20hdb30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20hdb30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10hdb2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20hdb20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20hdb20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20hdb20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10hdb20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80hdb18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20hdb30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20hdb39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10hdb20h,10h,2bh,10h,26h,30h,30h,80h,00HEND03生日歌ORG0000HJMPSTARTORG000BHJMPTIM0ORG0030HSTART:MOVTMOD,#01HMOVIE,#82HSTART0:MOV30H,#00HNEXT:MOVA,30HMOVDPTR,#TABLEMOVCA,@A+DPTRMOVR2,AJZEND0ANLA,#0FHMOVR5,AMOVA,R2SWAPAANLA,#0FHJNZSINGCLRTR0JMPD1SING:DECAMOV22H,ARLAMOVDPTR,#TABLE1MOVCA,@A+DPTRMOVTH0,AMOV21H,AMOVA,22HRLAINCAMOVCA,@A+DPTRMOVTL0,AMOV20H,ASETBTR0D1:CALLDELAYINC30HJMPNEXTEND0:CLRTR0JMPSTART0TIM0:PUSHACCPUSHPSWMOVTH0,21HMOVTL0,20HCPLP3.7POPPSWPOPACCRETIDELAY:MOVR7,#02D2:MOVR4,#187D3:MOVR3,#248DJNZR3,$DJNZR4,D3DJNZR7,D2DJNZR5,DELAYRETTABLE1:DW64260,64400,64524,64580DW64684,64777,64820,64898DW64968,65030,65058,65110DW65157,65178,65217TABLE:DB82H,01H,81H,94H,84HDB0B4H,0A4H,04HDB82H,01H,81H,94H,84HDB0C4H,0B4H,04HDB82H,01H,81H,0F4H,0D4HDB0B4H,0A4H,94HDB0E2H,01H,0E1H,0D4H,0B4HDB0C4H,0B4H,04HDB82H,01H,81H,94H,84HDB0B4H,0A4H,04HDB82H,01H,81H,94H,84HDB0C4H,0B4H,04HDB82H,01H,81H,0F4H,0D4HDB0B4H,0A4H,94HDB0E2H,01H,0E1H,0D4H,0B4HDB0C4H,0B4H,04HDB00HEND04八月桂花香ORG0000HLJMPSTARTORG000BHINC20H;中断服务,中断计数器加1MOVTH0,#0D8HMOVTL0,#0EFH;12M晶振,形成10毫秒中断RETISTART:MOVSP,#50HMOVTH0,#0D8HMOVTL0,#0EFHMOVTMOD,#01HMOVIE,#82HMUSIC0:NOPMOVDPTR,#DAT;表头地址送DPTRMOV20H,#00H;中断计数器清0MUSIC1:NOPCLRA;A清零MOVCA,@A+DPTR;查表取代码JZEND0;是00H,则结束CJNEA,#0FFH,MUSIC5;如果是休止符,往下执行LJMPMUSIC3MUSIC5:NOPMOVR6,A;R6=18H音符的频率INCDPTR;DPTR加一MOVA,#0MOVCA,@A+DPTR;取节拍代码送R7MOVR7,A;R7=30H音符发音的时间SETBTR0;启动计数MUSIC2:NOPCPLP2.3;P2.3是音乐输出引脚MOVA,R6MOVR3,A;籖3=R6=18HLCALLDELMOVA,R7CJNEA,20H,MUSIC2;中断计数器(20H)=R7否?;不等,则继续循环MOV20H,#00H;等于,则取下一代码INCDPTRLJMPMUSIC1MUSIC3:NOP;休止100毫秒CLRTR0MOVR2,#0DH;R2=13MUSIC4:NOPMOVR3,#0FFH;R3=255LCALLDELDJNZR2,MUSIC4INCDPTRLJMPMUSIC1END0:NOPMOVR2,#0FFH;歌曲结束,延时1秒后继续MUSIC6:MOVR3,#00HLCALLDELDJNZR2,MUSIC6LJMPMUSIC0DEL:NOPDEL3:MOVR4,#02HDEL4:NOPDJNZR4,DEL4NOPDJNZR3,DEL3RETNOPDAT:DB18H,30H,1CH,10HDB20H,40H,1CH,10HDB18H,10H,20H,10HDB1CH,10H,18H,40HDB1CH,20H,20H,20HDB1CH,20H,18H,20HDB20H,80H,0FFH,20HDB30H,1CH,10H,18HDB20H,15H,20H,1CHDB20H,20H,20H,26HDB40H,20H,20H,2BHDB20H,26H,20H,20HDB20H,30H,80H,0FFHDB20H,20H,1CH,10HDB18H,10H,20H,20HDB26H,20H,2BH,20HDB30H,20H,2BH,40HDB20H,20H,1CH,10HDB18H,10H,20H,20HDB26H,20H,2BH,20HDB30H,20H,2BH,40HDB20H,30H,1CH,10HDB18H,20H,15H,20HDB1CH,20H,20H,20HDB26H,40H,20H,20HDB2BH,20H,26H,20HDB20H,20H,30H,80HDB20H,30H,1CH,10HDB20H,10H,1CH,10HDB20H,20H,26H,20HDB2BH,20H,30H,20HDB2BH,40H,20H,15HDB1FH,05H,20H,10HDB1CH,10H,20H,20HDB26H,20H,2BH,20HDB30H,20H,2BH
本文标题:51单片机汇编语言音乐程序
链接地址:https://www.777doc.com/doc-5236594 .html