音乐盒设计层序_第1页
音乐盒设计层序_第2页
音乐盒设计层序_第3页
音乐盒设计层序_第4页
音乐盒设计层序_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、急急急! 求AT89C51单片机实训制作音乐盒程序编写!以下为电路原理图。谢谢.晶振是12M 2011-5-24 19:48 提问者: 傻傻的哇 | 浏览次数:1114次要求:演奏音乐模式和花样灯模式。演奏音乐模式:演奏完整的一首的歌曲,八路LED随着音乐变化。花样灯模式:八路LED变化出各种花样,蜂鸣器随着发出“嘀嘀”声2)按下按键1进入演奏音乐模式,再按切换歌曲,共两首歌曲。3)按下按键2进入花样灯模式,再按切换LED花样,共三种花样。我来帮他解答 输入内容已经达到长度限制还能输入 9999 字插入图片删除图片插入地图删除地图插入视频视频地图参考资料:匿名回答提交回答取消 2011-5-2

2、5 13:28 满意回答 OUT BIT P2.3 ;定义音频输出端口,p2.3N EQU 9;歌曲总数OUT_NUM EQU P0;数码管显视当前所放歌曲曲数 ORG 0000H AJMP MAIN ORG 0003H AJMP LAST_SONG ;外部中断0用于接上一曲歌按键 ORG 000BH AJMP F_T0 ;定时器0用于定时,作音符发生器用 ORG 0013Hq4: AJMP NEXT_SONG ;外部中断1接下一曲歌按键 ORG 001BH AJMP START_PAUSE ;定时器1用计数,这里用作中断,接开始/暂停键,初值为0ffH,方式2 ORG 0030HMAIN:

3、MOV SP,#60H MOV DPTR,#TABLE ;DPRT指向每首歌曲的入口地址的地址。 MOV R0,#30H ;R0中存入数据30H,这里在以30H开始的单元存放每首歌曲的入口地址,其中30H,31H存放 ;歌曲的节拍入口地址,32H,33H存放歌曲音符入口地址,每首歌占用四个存储存单元。 MOV R5,#00H ;R5中存放表TABLE中正在执行操作的序号 MOV R6,#1 ;R6存放正在设置入口信息的歌曲数SET_TAB: MOV A,R5 ;设置每首歌曲的入口信息,存放在以30H开始的存储单元中。 MOVC A,A+DPTR MOV R0,A INC R5 INC R0 M

4、OV A,R5 MOVC A,A+DPTR MOV R0,A INC R5 INC R0 MOV A,R5 MOVC A,A+DPTR MOV R0,A INC R0 INC R5 MOV A,R5 MOVC A,A+DPTR MOV R0,A INC R0 INC R5 INC R6 ;设置完一首歌曲后,歌曲数加一 CJNE R6,#N+1,SET_TAB ;是否设置完,没有便继续,否则进行下面的操作 ;* 对中断,计数器的相关参数进行设置 MOV TMOD, #61H;计数器0工作方式1,计数器1工作方式2 MOV TH1,#0FFH;给计数器1置初值0FFH,又由于是工作方式2,所以 M

5、OV TL1,#0FFH;计数器计数为1,相当于一外部中断。 SETB ET1 ;允许计数器1中断 SETB ET0 ;允许计数器具0中断 CLR PT0 ;计数器0为低优先级 SETB PT1 ;计数器1为高优先级 SETB IT0 ;外部中断0为跳沿触发 SETB PX0 ;高优先级 SETB IT1 ;外部中断1为跳沿触发 SETB PX1 ;高优先级 SETB EX1 ;允许外部中断1中断 SETB EX0 ;允许外部中断定0中断 SETB EA ;开中断总开关 SETB TR1 ;定时器1开始工作,作中断用 SETB OUT ;音频输出端口初始化 ;* ;设置结束 CLR F0 ;设

6、置F0=0,用来作暂停/播放的标置位用 MOV 22H,#01H ;22H单元中存放正在播放的歌曲编号 MOV DPTR,#OUT_TAB ;将正在播放的歌曲编号送数码管显视 MOV A,22H MOVC A,A+DPTR MOV OUT_NUM,A MOV R7,#00H ;R7中存放歌曲总信息的入口地址START0:MOV R4,#00H ;R4存放当前正在播放歌曲的第几个节拍数 MOV R0,#30H ;30H开始的单元中存放歌曲的入口信息 MOV A,R7 ;将歌曲的节拍表的入口地址送到DPTR ADD A,R0 MOV R0,A MOV DPH,R0 INC R0 MOV DPL,R

7、0 INC R0 MOV A,R4 INC R4 MOVC A,A+DPTR ;取出第一节拍数,其实第一个节拍不是歌曲的第一个节拍,而是表示几分音符;* MOV 26H,A ;将取出的音符数+节拍数保存在职26H单元中NEXT: MOV R0,#30H ;开始取出歌曲的第一个数据 MOV A,R7 ADD A,R0 MOV R0,A MOV DPH,R0 INC R0 MOV DPL,R0 INC R0 MOV A,R4 INC R4 MOVC A,A+DPTR;放在A中;* JZ END0 ;若为0,则表示为休止符,不唱,本次音符不唱, MOV R1,A ;不为0,取出节拍数 ANL A,#

8、0FH MOV R2,A MOV A,R1 SWAP A ANL A,#0FH JNZ SING ;音符不为0,唱 CLR TR0 ;为0,不唱,关频率发生器 SJMP SING1SING: DEC A ;开始唱,进行相应的数据处理 MOV R3,A RL A MOV DPH,R0 INC R0 MOV DPL,R0 INC R0 MOVC A,A+DPTR MOV 21H,A MOV TH0,A MOV A,R3 RL A INC A MOVC A,A+DPTR MOV 20H,A MOV TL0,A SETB TR0 ;开唱SING1:LCALL DELAY ;每个音符唱多久 JB F0,

9、FOR ;是否暂停, AJMP NEXT ;没有暂停,继续FOR: CLR TR0 ;暂停,不唱 JB F0,$ ;等待播放 AJMP NEXT ;开始播放END0: CLR TR0 ;不唱 MOV A,22H ;唱完处理 CJNE A,#N,WW ;是不是全部歌曲都唱完 MOV 22H,#01H ;全部唱完,则从第一首开始再唱 MOV R7,#00H MOV OUT_NUM,#B;数码管显视第一首歌曲编号 AJMP WWWWW: MOV A,R7 ;没有全部唱完,唱下一首,歌曲的入口信息调整 ADD A,#4 MOV R7,A INC 22H CLR EA PUSH DPH PUSH DPL

10、 MOV A,22H MOV DPTR,#OUT_TAB MOVC A,A+DPTR MOV OUT_NUM,A ;数码管显视相应的歌曲编号 POP DPL POP DPHWWW: SETB EA AJMP START0 ;开始下一首的演唱F_T0: MOV TH0,21H ;定时器0置初值 MOV TL0,20H CPL OUT ;频率产生 RETINEXT_SONG: PUSH ACC ;下一曲中断程序处理,保护现场 PUSH DPH PUSH DPL CLR EA ;关中断 MOV A,22H CJNE A,#N,Q ;是最后一首吗? MOV R7,#00H ;是最后一首,则R7指向第一

11、首,演唱第一首 MOV 22H,#01H AJMP BACKQ: INC 22H ;不是最后一首,唱下一首,R7内容加4,歌曲数加1 MOV A,R7 ADD A,#4 MOV R7,ABACK: MOV R4,#00H ;数码管显视相应的歌曲编号 MOV A,22H MOV DPTR,#OUT_TAB MOVC A,A+DPTR MOV OUT_NUM,A;* MOV B,R0 ;对下首要演唱的歌曲的几分拍进行调整,同时对R0中的内容进行保护 MOV R4,#00H MOV R0,#30H MOV A,R7 ADD A,R0 MOV R0,A MOV DPH,R0 INC R0 MOV DP

12、L,R0 INC R0 MOV A,R4 INC R4 MOVC A,A+DPTR MOV 26H,A ;结果存入26H单元中 DEC R4 MOV R0,B;恢复R0中的内容;* POP DPL;恢复现场 POP DPH POP ACC SETB EA RETI ;中断返回LAST_SONG: PUSH ACC ;上一曲中断程序处理开始,保护现场 PUSH DPH PUSH DPL CLR EA ;关中断 MOV A,22H ;曲目数送A CJNE A,#1,QQ ;是否是第一首 MOV 22H,#N ;是第一首歌曲 MOV B,#4 ;将R7指向最后一首歌曲 MOV A,#N-1 MUL

13、AB MOV R7,A AJMP BACK2 ;处理结束QQ: DEC 22H MOV A,R7 ;R7减4 SUBB A,#4 MOV R7,ABACK2: MOV R4,#00H MOV A,22H MOV DPTR,#OUT_TAB MOVC A,A+DPTR MOV OUT_NUM,A ;数码管显视相应歌曲的编号;* MOV B,R0;对下首要演唱的歌曲的几分拍进行调整,同时对R0中的内容进行保护 MOV R4,#00H MOV R0,#30H MOV A,R7 ADD A,R0 MOV R0,A MOV DPH,R0 INC R0 MOV DPL,R0 INC R0 MOV A,R4

14、 INC R4 MOVC A,A+DPTR MOV 26H,A ;结果存入26H单元中 DEC R4 MOV R0,B;R0中的内容恢复;* POP DPL ;恢复现场 POP DPH POP ACC SETB EA RETI ;中断返回START_PAUSE:CPL F0 ;开始/暂停中断处理程序,将标置位取反 JB F0,RETURN ;为1返回 SETB TR0 ;为0则播放RETURN: RETI ;中断返回DELAY: MOV 27H,26H ;音符演奏时间控制D2: MOV 28H,#125D3: MOV 29H,#248 DJNZ 29H,$ DJNZ 28H,D3 DJNZ 2

15、7H,D2 DJNZ R2,DELAY RET;OUT_TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,73H ;共阴数码管显视用OUT_TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,88H,83H,0C6H,0A1H,86H,8EH,0FFH ;共阳TABLE: DW SONG1,TABLE1,SONG2,TABLE2,SONG3,TABLE3,SONG4,TABLE4 ,SONG5,TABLE5,SONG6,TABLE6,SONG7,T

16、ABLE7,SONG8,TABLE8TABLE1:DW 64580,64684,64777,64820 DW 64898,64968,65030,64260 DW 64400,64524,65058,63835,64021 SONG1: ;精忠报国DB 66H,52H,36H,22H,12H,12H,22H,32H,98H,84H,82H,92H,14H,12H,22HDB 32H,52H,22H,42H,38H,66H,52H,36H,22H,12H,22H,22H,32H,98HDB 24H,22H,32H,54H,52H,32H,92H,12H,92H,82H,98H,66H,52H,3

17、6H,22HDB 12H,12H,22H,32H,98H,84H,82H,92H,14H,12H,22H,32H,52H,22H,42H,38HDB 66H,52H,36H,22H,12H,22H,22H,32H,98H,24H,22H,32H,54H,52H,32HDB 22H,12H,92H,82H,98H,14H,24H,34H,44H,64H,0B4H,64H,32H,52HDB 62H,0B2H,62H,52H,38H,24H,22H,32H,54H,52H,62H,52H,32H,32H,22H,38HDB 64H,0B4H,64H,32H,52H,62H,0B2H,62H,52H

18、,38H,22H,22H,22H,32H,52H,52HDB 52H,62H,7FH,74H,04H,58H,6FHDB 00TABLE2:DW 64580,64684,64777,64820 DW 64898,64968,65030,64260 DW 64400,64524,65058,63835,64021 SONG2: DB 02H,82H ;月亮代表我的心DB 16H,32H,54H,02H,52HDB 0A6H,32H,54H,02H,52HDB 64H,74H,0B6H,64HDB 52H,5CH,32H,22HDB 16H,12H,14H,32H,22HDB 16H,12H,14

19、H,22H,32HDB 26H,12H,94H,22H,32HDB 2CHDB 32H,52HDB 36H,22H,14H,54HDB 0ACH,92H,0A2HDB 96H,0A2H,96H,82HDB 3CH,54HDB 36H,22H,14H,54HDB 0ACH,92H,0A2HDB 16H,12H,14H,22H,32HDB 2CH,02H,82HDB 16H,32H,56H,12HDB 0A6H,32H,56H,52HDB 66H,72H,0B6H,62HDB 62H,52H,58H,32H,22HDB 16H,12H,14H,32H,22HDB 16H,12H,14H,22H,3

20、2HDB 26H,92H,0A4H,12H,22HDB 1CHDB 00TABLE3: DW 64580,64684,64777,64820 DW 64898,64968,65030,64260 DW 64400,64524,65058,63835,64021 SONG3: DB 0d4H,84H,94H,82H,92H ;看我七十二变DB 12H,22H,82H,92H,02H,92H,82H,0d2HDB 82H,92H,14H,84H,02H,0d1H,0d1HDB 0c2H,0d2H,84H,0d2H,0d2H,82H,82HDB 84H,82H,82H,94H,82H,0d2HDB

21、82H,82H,82H,92H,02H,82H,82H,0d2HDB 0c4H,84H,0d4H,92H,0d2HDB 82H,0d2H,82H,92H,98HDB 04H,94H,88HDB 04H,94H,88HDB 04H,94H,88HDB 04H,94H,88H,04HDB 32H,32H,22H,12H,02H,92H,12H,92HDB 32H,32H,22H,12H,02H,92H,12H,92HDB 32H,32H,22H,12H,02H,92H,12H,22HDB 54H,44H,34H,12H,22HDB 34H,22H,12H,02H,92H,12H,92HDB 32H

22、,32H,22H,12H,02H,92H,12H,92HDB 32H,32H,22H,12H,02H,92H,12H,22HDB 54H,44H,32H,22H,12H,92HDB 00TABLE4:DW 64580,64684,64777,64820 DW 64898,64968,65030,64260 DW 64400,64524,65058,63835,64021 SONG4:DB 82H,92H,12H,14H,12H,14H,92H,82H,12H,14H,22H,14H,92H,12H,22H,24H ;大海DB 22H,24H,12H,92H,22H,24H,32H,24H,32

23、H,52H,62H,54H,52H,64H,52H,32HDB 22H,32H,22H,12H,94H,82H,92H,12H,14H,12H,14H,94H,1cHDB 82H,92H,12H,14H,12H,14H,92H,82H,12H,14H,22H,14H,92H,12H,22H,24HDB 22H,24H,12H,92H,22H,24H,32H,24H,32H,52H,62H,54H,52H,64H,52H,32HDB 22H,32H,22H,12H,94H,82H,92H,12H,14H,12H,14H,22H,12H,1cH,32H,52HDB 62H,64H,62H,64H,

24、0b2H,62H,52H,54H,62H,54H,32H,22HDB 12H,14H,12H,14H,24H,3cH,32H,22H,12H,14H,12H,14H,0b2H,62H,52H,54H,62H,54H,32H,52HDB 66H,0b2H,0b4H,62H,52H,5cH,32H,52H,62H,64H,62H,64H,0b2H,62H,52H,54HDB 62H,54H,32H,22H,12H,14H,12H,14H,54H,3cH,32H,22H,12H,14H,12H,14H,22H,32HDB 52H,54H,32H,54H,32H,52H,6fH,04H,02H,92H

25、,32H,24H,12H,1fHDB 00TABLE5:DW 64021,64103,64260,64400 ,64524,64580,64684,64777,64820,64898,64968,65030,64934SONG5: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

26、,11H,24HDB 32H,52H,52H,32H,22H,12H,24H,32H,52H,52H,32H,62H,52H,61H,51H,DB 31H,21H,21H,31H,21H,11H,1CHDB 21H,31H,22H,23H,31H,21H,18H,02H,0B2H,0BCH,0B4H,72H,61H,51H,72H,61H,DB 71H,61H,51H,61H,71H,61H,6FHDB 86H,94H,12H,22H,32H,52H,64H,62H,51H,31H,52H,21H,31H,21H,33H,62H,0B2H,0B2H,62H,DB 51H,61H,51H,31H

27、,54HDB 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,54HDB 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,62HDB 51H,31H,31H,21H,11H,91H,23H,31H,21H,1CH,12H,24H,32H,62H,51H,31H,34H,

28、0B4H,72H,DB 61H,51H,63H,71H,64HDB 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,81HDB 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,21HDB 00;*绿岛小夜曲TABLE6:DW 64

29、021,6103,64260,64400,64524,64580,64624,64777,64820,64898,64958,65030,65058,65110,65157SONG6: DB 06H DB 0A2H,0B2H,0D2H,0B2H,0A4H,0B2H,0D2H DB 0B2H,0A2H,82H,72H,88H DB 72H,82H,0A2H,82H,72H,62H,42H,62H DB 38H,38H DB 0A4H,02H,0B2H,0A4H,84H DB 72H,82H,72H,62H,72H,84H,72H DB 64H,62H,12H,34H,02H,42H DB 38H

30、,38H DB 44H,02H,32H,44H,64H DB 72H,82H,72H,62H,72H,84H,0A2H DB 72H,74H,82H,0A4H,02H,062H DB 0A8H,0A8H DB 0B2H,0B4H,0A2H,84H,82H,72H DB 62H,72H,82H,0A2H,88H DB 72H,74H,62H,42H,32H,32H,62H DB 78H,78H DB 82H,84H,72H,82H,0A2H,84H DB 72H,82H,72H,62H,48H DB 32H,0A2H,82H,0F2H,0A2H,0B2H,82H,72H DB 68H,68H D

31、B 0B2H,0B2H,0B2H,0A2H,82H,84H,02H DB 72H,74H,62H,42H,32H,42H,62H DB 78H,78H DB 0A2H,0B2H,0A2H,72H,82H,84H,82H DB 72H,74H,62H,44H,64H DB 0A8H,0A4H,02H,0A2H DB 0A2H,0B1H,0A1H,82H,0A2H,0B4H,0B2H,0C2H DB 0A2H,0B2H,0A2H,82H,78H DB 84H,72H,62H,44H,02H,62H DB 72H,81H,71H,62H,72H,84H,02H,0A2H DB 0B4H,02H,82

32、H,74H,82H,72H DB 68H,68H DB 00TABLE7: DW 64260,64400,64521,64580DW 64684,64777,64820,64898DW 64968,65030,65058,65110DW 65157,65178,65217SONG7: ;乐曲名称梁祝DB 02H,82H,62H,52H,48H,02H,52H,32H,22H,18HDB 83H,91H,72H,62H,51H,61H,71H,61H,83H,61HDB 81H,51H,61H,71H,61H,51H,46H,82H,32H,52HDB 22H,42H,16H,21H,41H,18H,0E4H,13H,21H,43HDB 51H,21H,41H,12H,83H,81H,61H,81H,58H,53HDB 61H,31H,22H,13H,21H,42H,52H,0E2H,42H,21HDB 11H,91H,41H,18H,63H,81H,32H,52H,21H,41H,DB 16H,0E4H,11H,21H,31H,51H,26H,11H,21H,43HDB 51H,82H,62H,52H,61H,51H,42

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论