急需单片机音乐程序一个,不要“祝你平安和八月桂花香”这两首,因为我已经有,我需要另外一首!谢谢。。
展开全部
看看:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/88bfff323ec42ef21b4cff09.html
-------------------
;生日快乐歌的程序
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
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/88bfff323ec42ef21b4cff09.html
-------------------
;生日快乐歌的程序
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
展开全部
;八月桂花香唱歌程序。
;***************************************************************************
;* sxj1974@163.com (51c51 test web) www.8951.com *
;* Create by :石学军 www.51c51.com 更多例程请登陆网站 *
;***************************************************************************
ORG 0000H
LJMP START
ORG 000BH ;中断入口
INC 20H ;中断服务程序,中断计数器加1
MOV TH0,#0D8H
MOV TL0,#0EFH ;12M晶振,形成10毫秒中断
RETI
START:
MOV SP,#50H
MOV TH0,#0D8H
MOV TL0,#0EFH
MOV TMOD,#01H ;设定定时器工作方式
MOV IE,#82H
MUSIC0:
NOP
MOV DPTR,#DAT ;表头地址送DPTR
MOV 20H,#00H ;中断计数器清0
MOV B,#00H ;表序号清0
MUSIC1:
NOP
CLR A
MOVC A,@A+DPTR ;查表取代码
JZ END0 ;是00H,则结束
CJNE A,#0FFH,MUSIC5
LJMP MUSIC3
MUSIC5:
NOP
MOV R6,A
INC DPTR
MOV A,B
MOVC A,@A+DPTR ;取节拍代码送R7
MOV R7,A
SETB TR0 ;启动计数
MUSIC2:
NOP
CPL P3.3
MOV A,R6
MOV R3,A
CPL A
MOV P1,A ;显示(修改者加入的显示)
CPL A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否?
;不等,则继续循环
MOV 20H,#00H ;等于,则取下一代码
INC DPTR
LJMP MUSIC1
MUSIC3:
NOP
CLR TR0 ;休止100毫秒
MOV R2,#0DH
MUSIC4:
NOP
MOV R3,#0FFH
LCALL DEL
DJNZ R2,MUSIC4
INC DPTR
LJMP MUSIC1
END0:
NOP
MOV R2,#64H ;歌曲结束,延时1秒后继续
MUSIC6:
MOV R3,#00H
LCALL DEL
DJNZ R2,MUSIC6
LJMP MUSIC0
DEL: ;延时子程序
NOP
DEL3:
MOV R4,#05H
DEL4:
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
DAT: ;数据表格存放在ROM中。
DB 18H, 30H, 1CH, 10H
DB 20H, 40H, 1CH, 10H
DB 18H, 10H, 20H, 10H
DB 1CH, 10H, 18H, 40H
DB 1CH, 20H, 20H, 20H
DB 1CH, 20H, 18H, 20H
DB 20H, 80H, 0FFH,20H
DB 30H, 1CH, 10H, 18H
DB 20H, 15H, 20H, 1CH
DB 20H, 20H, 20H, 26H
DB 40H, 20H, 20H, 2BH
DB 20H, 26H, 20H, 20H
DB 20H, 30H, 80H, 0FFH
DB 20H, 20H, 1CH, 10H
DB 18H, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 20H, 1CH, 10H
DB 18H, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 30H, 1CH, 10H
DB 18H, 20H, 15H, 20H
DB 1CH, 20H, 20H, 20H
DB 26H, 40H, 20H, 20H
DB 2BH, 20H, 26H, 20H
DB 20H, 20H, 30H, 80H
DB 20H, 30H, 1CH, 10H
DB 20H, 10H, 1CH, 10H
DB 20H, 20H, 26H, 20H
DB 2BH, 20H, 30H, 20H
DB 2BH, 40H, 20H, 15H
DB 1FH, 05H, 20H, 10H
DB 1CH, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 30H, 1CH, 10H
DB 18H, 20H, 15H, 20H
DB 1CH, 20H, 20H, 20H
DB 26H, 40H, 20H, 20H
DB 2BH, 20H, 26H, 20H
DB 20H, 20H, 30H, 30H
DB 20H, 30H, 1CH, 10H
DB 18H, 40H, 1CH, 20H
DB 20H, 20H, 26H, 40H
DB 13H, 60H, 18H, 20H
DB 15H, 40H, 13H, 40H
DB 18H, 80H, 00H
end
;***************************************************************************
;* sxj1974@163.com (51c51 test web) www.8951.com *
;* Create by :石学军 www.51c51.com 更多例程请登陆网站 *
;***************************************************************************
ORG 0000H
LJMP START
ORG 000BH ;中断入口
INC 20H ;中断服务程序,中断计数器加1
MOV TH0,#0D8H
MOV TL0,#0EFH ;12M晶振,形成10毫秒中断
RETI
START:
MOV SP,#50H
MOV TH0,#0D8H
MOV TL0,#0EFH
MOV TMOD,#01H ;设定定时器工作方式
MOV IE,#82H
MUSIC0:
NOP
MOV DPTR,#DAT ;表头地址送DPTR
MOV 20H,#00H ;中断计数器清0
MOV B,#00H ;表序号清0
MUSIC1:
NOP
CLR A
MOVC A,@A+DPTR ;查表取代码
JZ END0 ;是00H,则结束
CJNE A,#0FFH,MUSIC5
LJMP MUSIC3
MUSIC5:
NOP
MOV R6,A
INC DPTR
MOV A,B
MOVC A,@A+DPTR ;取节拍代码送R7
MOV R7,A
SETB TR0 ;启动计数
MUSIC2:
NOP
CPL P3.3
MOV A,R6
MOV R3,A
CPL A
MOV P1,A ;显示(修改者加入的显示)
CPL A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否?
;不等,则继续循环
MOV 20H,#00H ;等于,则取下一代码
INC DPTR
LJMP MUSIC1
MUSIC3:
NOP
CLR TR0 ;休止100毫秒
MOV R2,#0DH
MUSIC4:
NOP
MOV R3,#0FFH
LCALL DEL
DJNZ R2,MUSIC4
INC DPTR
LJMP MUSIC1
END0:
NOP
MOV R2,#64H ;歌曲结束,延时1秒后继续
MUSIC6:
MOV R3,#00H
LCALL DEL
DJNZ R2,MUSIC6
LJMP MUSIC0
DEL: ;延时子程序
NOP
DEL3:
MOV R4,#05H
DEL4:
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
DAT: ;数据表格存放在ROM中。
DB 18H, 30H, 1CH, 10H
DB 20H, 40H, 1CH, 10H
DB 18H, 10H, 20H, 10H
DB 1CH, 10H, 18H, 40H
DB 1CH, 20H, 20H, 20H
DB 1CH, 20H, 18H, 20H
DB 20H, 80H, 0FFH,20H
DB 30H, 1CH, 10H, 18H
DB 20H, 15H, 20H, 1CH
DB 20H, 20H, 20H, 26H
DB 40H, 20H, 20H, 2BH
DB 20H, 26H, 20H, 20H
DB 20H, 30H, 80H, 0FFH
DB 20H, 20H, 1CH, 10H
DB 18H, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 20H, 1CH, 10H
DB 18H, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 30H, 1CH, 10H
DB 18H, 20H, 15H, 20H
DB 1CH, 20H, 20H, 20H
DB 26H, 40H, 20H, 20H
DB 2BH, 20H, 26H, 20H
DB 20H, 20H, 30H, 80H
DB 20H, 30H, 1CH, 10H
DB 20H, 10H, 1CH, 10H
DB 20H, 20H, 26H, 20H
DB 2BH, 20H, 30H, 20H
DB 2BH, 40H, 20H, 15H
DB 1FH, 05H, 20H, 10H
DB 1CH, 10H, 20H, 20H
DB 26H, 20H, 2BH, 20H
DB 30H, 20H, 2BH, 40H
DB 20H, 30H, 1CH, 10H
DB 18H, 20H, 15H, 20H
DB 1CH, 20H, 20H, 20H
DB 26H, 40H, 20H, 20H
DB 2BH, 20H, 26H, 20H
DB 20H, 20H, 30H, 30H
DB 20H, 30H, 1CH, 10H
DB 18H, 40H, 1CH, 20H
DB 20H, 20H, 26H, 40H
DB 13H, 60H, 18H, 20H
DB 15H, 40H, 13H, 40H
DB 18H, 80H, 00H
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询