求 单片机中用汇编语言写的简单的音乐演示

2024-11-25 02:31:00
推荐回答(1个)
回答1:

ORG 00H
JMP START
ORG 0BH
JMP TIM0
START:MOV TMOD,#01H
MOV IE,#10000010B
CLR TR0
MOV P2,#0FFH
MOV A,P2
MOV P2,#0FFH
RR A
RR A
RR A
ANL A,#0FH ;将选择的音乐号放入A
MOV 40H,A
JB P3.3,$ ;P3.3 为起始信号 片选信号

START0:MOV 30H,#00H
NEXT: MOV A,40H
JB P3.3,START
CJNE A,#00H,MUSIC1
MOV DPTR,#TABLE ;生日快乐的TABLE
JMP CON
MUSIC1: CJNE A,#01,MUSIC2
MOV DPTR,#TABLE1
JMP CON
MUSIC2:CJNE A,#02,MUSIC3
MOV DPTR,#TABLE2
JMP CON
MUSIC3:CJNE A,#03,MUSIC4
MOV DPTR,#TABLE3
JMP CON
MUSIC4:CJNE A,#04,MUSIC5
MOV DPTR,#TABLE4
JMP CON
MUSIC5:CJNE A,#05,MUSIC6
MOV DPTR,#TABLE5
JMP CON
MUSIC6:CJNE A,#06,MUSIC7
MOV DPTR,#TABLE6
JMP CON
MUSIC7:SETB P2.6
JMP START ;共7首歌,这个时候不发音

CON: MOV A,30H
MOVC A,@A+DPTR
MOV R2,A
JZ END0
ANL A,#0FH
MOV R5,A
MOV A,R2
SWAP A
ANL A,#0FH
JNZ SING
CLR TR0
JMP D1
SING: mov 50H,A
MOV A,40H
CJNE A,#00H,MODE1
MOV DPTR,#TABLE0 ;TABLE1
JMP CONT
MODE1: MOV DPTR,#TABLE01

CONT: MOV A,50H
DEC A
MOV 22H,A
RL A

MOVC A,@A+DPTR
MOV TH0,A
MOV 21H,A
MOV A,22H
RL A
INC A
MOVC A,@A+DPTR
MOV TL0,A
MOV 20H,A
SETB TR0
D1: CALL DELAY

INC 30H
JMP NEXT
END0: CLR TR0
JMP START0
TIM0: PUSH ACC
PUSH PSW
MOV TL0,20H
MOV TH0,21H

CPL P2.6

POP PSW
POP ACC
RETI
DELAY: MOV R7,#02
D2: MOV R4,#125
D3: MOV R3,#248
;JB P2.7,START
DJNZ R3,$
DJNZ R4,D3
DJNZ R7,D2
DJNZ R5,DELAY
RET
TABLE0:
DW 64260,64400,64524,64580
DW 64684,64777,64820,64898
DW 64968,65030,65058,65110
DW 65157,65178,65217

TABLE01:
DW 64260,64400,64524,64580
DW 64684,64777,64820,64898
DW 64968,65030,65058,65110
DW 65157,65178,65217

TABLE: ;生日快乐
DB 82H,01H,81H,94H,84H
DB 0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H
DB 0C4H,0B4H,04H

DB 82H,01H,81H,0F4H,0D4H
DB 0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H
DB 0C4H,0B4H,04H

DB 82H,01H,81H,94H,84H
DB 0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H
DB 0C4H,0B4H,04H

DB 82H,01H,81H,0F4H,0D4H
DB 0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H
DB 0C4H,0B4H,04H
TABLE1: ;三只小猫
DB 62H,82H,82H,62H,98h
DB 92H,0B2H,0B2H,82H,98H
DB 62H,82H,82H,52H,68H
DB 92H,0B2H,0B2H,82H,98H

DB 62H,82H,82H,62H,92H,92H,94H
DB 92H,0B2H,0B2H,92H,84H,94H
DB 0B8H,0B4H,04H

TABLE2: ;两只老虎
DB 44H,54H,64H,44H
DB 44H,54H,64H,44H
DB 64H,74H,88H
DB 64H,74H,88H

DB 82H,92H,82H,72H,64H,44H
DB 82H,92H,82H,72H,64H,44H
DB 44H,84H,48H
DB 44H,84H,48H

TABLE3: ;哈巴狗
DB 42H,42H,42H,52H,64h,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H

DB 42H,42H,42H,52H,64h,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H

TABLE4: ;兰花草
DB 42H,82H,82H,82H,02H,72h
DB 62H,72H,62H,52H,48H
DB 0B2H,0B2H,0B2H,0B2H,0B4H,02H,0AH

DB 12H,0A2H,0D2H,92H,88H
DB 82H,0B2H,0B2H,0A2H,84H,02H,72H
DB 62H,72H,62H,52H,44H,02H,12H

DB 12H,62H,62H,52H,44H,02H,82H
DB 72H,62H,52H,32H,48H

TABLE5: ;妹妹背着洋娃娃
DB 84H,02H,82H,64H,54h
DB 64H,54H,48H
DB 64H,02H,52H,44H,24H
DB 14H,24H,18H

DB 24H,02H,22H,42H,24H
DB 44H,54H,68H
DB 54H,02H,52H,84H,84H
DB 54H,64H,48H

TABLE6: ;不倒翁
DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44h
DB 62H,82H,42H,62H,58H

DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44h
DB 52H,42H,52H,62H,48H
DB 00
END

7首简单音乐的汇编代码