急需单片机音乐程序一个,不要“祝你平安和八月桂花香”这两首,因为我已经有,我需要另外一首!谢谢。。
1个回答
展开全部
;生日快乐歌的程序
ORG 0000H
SJMP START
ORG 000BH
LJMP TIM0
;-------------------------------------------
START:
MOV TMOD, #01H
MOV IE, #82H
;-------------------------------------------
START0:
MOV 30H, #0
;-------------------------------------------
GET_TONE:
MOV A, 30H
MOV DPTR, #TAB
MOVC A, @A+DPTR //假设取到82H
MOV R2, A //谱码82H存到R2
JZ END0 //是否取到结束码00H?
ANL A, #0FH //取(低四位)节拍码2
MOV R5, A //节拍码存于R5=2
MOV A, R2
SWAP A
ANL A, #0FH //取(高四位)音符码8
JNZ SING //取到的音符码是否为0
CLR TR0 //是,不发音
D1:
CALL DELAY
INC 30H
JMP GET_TONE
;-------------------------------------------
SING:
DEC A
MOV 22H, A //22H=07H
RL A //A=2*07H
MOV DPTR, #TAB1
MOVC A, @A+DPTR
MOV TH0, A
MOV 21H, A //21h=64898
MOV A, 22H
RL A
INC A
MOVC A, @A+DPTR
MOV TL0, A
MOV 20H, A //20h=64968
SETB TR0
SJMP D1
;-------------------------------------------
END0: CLR TR0
JMP START0
;-------------------------------------------
TIM0:
MOV TL0, 20H
MOV TH0, 21H
CPL P3.7 ;外接扬声器 发音
RETI
;-------------------------------------------
DELAY: MOV R7, #02
D2: MOV R4, #125
D3: MOV R3, #248
DJNZ R3, $
DJNZ R4, D3
DJNZ R7, D2
DJNZ R5, DELAY
RET
TAB1: DW 64260,64400,64524,64580,64684,64777,64820
DW 64898,64968,65030,65058,65110,65157,65178,65217
TAB:
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 00H
END
ORG 0000H
SJMP START
ORG 000BH
LJMP TIM0
;-------------------------------------------
START:
MOV TMOD, #01H
MOV IE, #82H
;-------------------------------------------
START0:
MOV 30H, #0
;-------------------------------------------
GET_TONE:
MOV A, 30H
MOV DPTR, #TAB
MOVC A, @A+DPTR //假设取到82H
MOV R2, A //谱码82H存到R2
JZ END0 //是否取到结束码00H?
ANL A, #0FH //取(低四位)节拍码2
MOV R5, A //节拍码存于R5=2
MOV A, R2
SWAP A
ANL A, #0FH //取(高四位)音符码8
JNZ SING //取到的音符码是否为0
CLR TR0 //是,不发音
D1:
CALL DELAY
INC 30H
JMP GET_TONE
;-------------------------------------------
SING:
DEC A
MOV 22H, A //22H=07H
RL A //A=2*07H
MOV DPTR, #TAB1
MOVC A, @A+DPTR
MOV TH0, A
MOV 21H, A //21h=64898
MOV A, 22H
RL A
INC A
MOVC A, @A+DPTR
MOV TL0, A
MOV 20H, A //20h=64968
SETB TR0
SJMP D1
;-------------------------------------------
END0: CLR TR0
JMP START0
;-------------------------------------------
TIM0:
MOV TL0, 20H
MOV TH0, 21H
CPL P3.7 ;外接扬声器 发音
RETI
;-------------------------------------------
DELAY: MOV R7, #02
D2: MOV R4, #125
D3: MOV R3, #248
DJNZ R3, $
DJNZ R4, D3
DJNZ R7, D2
DJNZ R5, DELAY
RET
TAB1: DW 64260,64400,64524,64580,64684,64777,64820
DW 64898,64968,65030,65058,65110,65157,65178,65217
TAB:
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 00H
END
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询