您的位置 首页 测评

根据51单片机的音乐播映程序

;本程序的单片机晶振采用11.0592MHZ;l程序中共有两首歌,后面一首为世上只有妈妈好.两首歌曲表的格式不同,若有任何疑问请留言

;本程序的单片机晶振选用11.0592MHZ

;l程序中共有两首歌,后边一首为世上只要妈妈好.两首歌曲表的格局不同,若有任何疑问请留言.

;刀郎的<<2002年的第一场雪>>
SPK BIT P0.0

ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TIMER0

MAIN:
MOV TMOD,#01H ;置CT0守时工作方式1
MOV IE,#82H;CPU开中止,CT0开中止

MOV R5,#0
PLAY:
MOV A,R5
MOV DPTR,#TABLE1
MOVC A,@A+DPTR
MOVR6,A
INC R5
MOV A,R5
MOVC A,@A+DPTR
MOVR7,A
INC R5
MOV A,R5
MOVC A,@A+DPTR
JNZ PLAY1
MOV R5,#0
LJMP NEXT
PLAY1:
MOV B,#3
MUL AB
MOV R2,A
MOV B,#7
MOV A,R7
MUL AB
ADD A,R6
DEC A
MOV R6,A
MOV DPTR,#FREQH
MOVC A,@A+DPTR
MOV R4,A
MOV DPTR,#FREQL
MOV A,R6
MOVC A,@A+DPTR
MOV R3,A
LCALL SONG;调用音符播映程序
INC R5
SJMP PLAY;转入调用下一个音符OV R3,A


MOV R5,#00H
NEXT:
MOV A,R5;R5寄存取数的变地址
MOV DPTR,#TABLE ;DPTR置音高节拍表首地址
MOVC A,@A+DPTR ;从音高节拍表取中取音高高位参数
MOV R4,A;R4寄存音高高位参数
INC R5
MOV A,R5
MOVC A,@A+DPTR ;从音高节拍表取中取音高低位参数
MOV R3,A;R3寄存音高低位参数
INC R5
MOV A,R5
MOVC A,@A+DPTR ;从音高节拍表取中取节拍参数
JNZ NEXT1
MOV R5,#00H
LJMP PLAY;唱完后循环(节拍参数为#00H表明歌曲完毕)
NEXT1:
MOV R2,A;R2寄存节拍参数
LCALL SONG;调用音符播映程序
INC R5
SJMP NEXT;转入调用下一个音符
SONG:
MOV TH0,R4
MOV TL0,R3
SETB TR0;发动CT0(开端唱某一音符)
DELAY:
MOV R1,#85H;节拍延时(即某一音符唱多长时间)
DEL1:
MOV R0,#0FFH
DEL0:
NOP
NOP
NOP
DJNZ R0,DEL0
DJNZ R1,DEL1
DJNZ R2,DELAY
CLR TR0;制止CT0(某一音符唱完后中止)
RET
TIMER0:;守时中止程序(用于决议某一音符唱多高)
CPL SPK
MOV TH0,R4
MOV TL0,R3
RETI
TABLE: ;音高节拍表,休止符用”FFH,FFH”,完毕用节拍为00H表明
DB 0FFH,0FFH,01H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H
DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,02H,0FFH,0FFH,01H,0FCH, 0BH,02H
DB 0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H
DB 0FBH, 8FH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H,0FFH,0FFH,01H
DB 0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,04H,0FDH, 08H,02H,0FDH, 08H,02H
DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,04H,0FDH, 08H,06H
DB 0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH, 03H,02H,0FAH, 14H,02H
DB 0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H
DB 0FFH,0FFH,01H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H
DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,04H,0FDH, 08H,06H
DB 0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH, 03H,02H,0FAH, 14H,02H
DB 0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H, 00H, 00H,00H

TABLE1:
DB6,2,3,5,2,1,3,2,2, 5,2,2, 1,3,2, 6,2,1, 5,2,1
DB6,2,4,3,2,2,5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1
DB6,1,1,5,2,1,3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2
DB5,2,1,6,2,1,3,2,2, 2,2,2, 1,2,4, 5,2,3, 3,2,1
DB2,2,1,1,2,1,6,1,1, 1,2,1, 5,1,6, 0,0,0
; 音阶频率表
FREQH:
DB0F2H,0F3H,0F5H,0F5H,0F6H,0F7H,0F8H
DB0F9H,0F9H,0FAH,0FAH,0FBH,0FBH,0FCH, 0FCH ;1,2,3,4,5,6,7,8,i
DB0FCH,0FDH,0FDH,0FDH,0FDH,0FEH
DB0FEH,0FEH,0FEH,0FEH,0FEH,0FEH,0FFH
FREQL:
DB42H, 0C1H, 17H, 0B6H,0D0H,0D1H,0B6H
DB21H, 0E1H, 8CH, 0D8H,68H, 0E9H, 5BH,8FH ;1,2,3,4,5,6,7,8,i
DB0EEH,44H,6BH,0B4H,0F4H,2DH
DB47H, 77H,0A2H,0B6H,0DAH,0FAH,16H
END


END

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ceping/258358.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部