跪求基于51单片机的汇编语言音乐盒程序
根据此电路图写程序,要求按开关换歌,液晶屏显示,此程序在百度文库中有,但是却是错误的,有些地方不全,百度文库中叫“1基于AT89C51单片机的音乐盒的设计”,附上电路图和...
根据此电路图写程序,要求按开关换歌,液晶屏显示,此程序在百度文库中有,但是却是错误的,有些地方不全,百度文库中叫 “1基于AT89C51单片机的音乐盒的设计”,附上电路图和要求,希望高手能帮我改好,必当重谢!先悬赏20分,成功之后追加50分!
3.1 硬件电路
本设计中用到了AT89C51单片机,4*4键盘,蜂鸣器,16*2 LCD等硬件电路常用元器件。
3.1.1 时钟复位电路
时钟电路由单片机XTAL1、 XTAL2引脚外接晶振(12MHz)及起振电容C1、C2(均为30pf)组成
3.1.2 按键输入电路
按键输入电路由4*4矩阵键盘组成, P1口作为输入控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列。
3.1.3 输出显示电路
用P2.0~P2.2作为LCD的RS、R/W、E的控制信号;用P0.0~P0.7作为LCD的D0~D7的控制信号。由于P0口作为输出,应加上拉电阻。
用P3.7口控制蜂鸣器。当键盘有键按下时,判断键值,启动计数器T0,产生一定频率的脉冲,驱动蜂鸣器,放出乐曲。同时启动定时器T1,显示乐曲播放的时间,并驱动LCD,显示歌曲号及播放时间。
(1) 硬件电路中用P1.0~P1.7控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列;
(2) 用P2.0~P2.2作为LCD的RS、R/W、E的控制信号;
(3)用P0.0~P0.7作为LCD的D0~D7的控制信号;
(4) 用P3.7口控制蜂鸣器;
(5) 电路为12MHz晶振频率工作,起振电路中C1,C2均为30pf。
不管是C还是汇编,现在电路已经焊完了,只要好使就行! 展开
3.1 硬件电路
本设计中用到了AT89C51单片机,4*4键盘,蜂鸣器,16*2 LCD等硬件电路常用元器件。
3.1.1 时钟复位电路
时钟电路由单片机XTAL1、 XTAL2引脚外接晶振(12MHz)及起振电容C1、C2(均为30pf)组成
3.1.2 按键输入电路
按键输入电路由4*4矩阵键盘组成, P1口作为输入控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列。
3.1.3 输出显示电路
用P2.0~P2.2作为LCD的RS、R/W、E的控制信号;用P0.0~P0.7作为LCD的D0~D7的控制信号。由于P0口作为输出,应加上拉电阻。
用P3.7口控制蜂鸣器。当键盘有键按下时,判断键值,启动计数器T0,产生一定频率的脉冲,驱动蜂鸣器,放出乐曲。同时启动定时器T1,显示乐曲播放的时间,并驱动LCD,显示歌曲号及播放时间。
(1) 硬件电路中用P1.0~P1.7控制按键,其中P1.0~P1.3扫描行,P1.4~P1.7扫描列;
(2) 用P2.0~P2.2作为LCD的RS、R/W、E的控制信号;
(3)用P0.0~P0.7作为LCD的D0~D7的控制信号;
(4) 用P3.7口控制蜂鸣器;
(5) 电路为12MHz晶振频率工作,起振电路中C1,C2均为30pf。
不管是C还是汇编,现在电路已经焊完了,只要好使就行! 展开
3个回答
展开全部
OUT BIT P2.3 //该引脚接蜂鸣器
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 OUT
MOV A,R6
MOV R3,A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否?
;不等,则继续循环
MOV 20H,#00H ;等于,则取下一代码
INC DPTR
; INC B
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,#02H
DEL4:
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
NOP
DAT:
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
END
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 OUT
MOV A,R6
MOV R3,A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否?
;不等,则继续循环
MOV 20H,#00H ;等于,则取下一代码
INC DPTR
; INC B
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,#02H
DEL4:
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
NOP
DAT:
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
END
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询