單片機(jī)音樂程序
;---------CLOCK(02)----------
T1INT: MOV TL1,#0F0H
MOV TH1,#0D8H
PUSH PSW
PUSH ACC
INC JPCLK
INC GENCLK
INC SNSDCLK
MOV A,SNSDCLK
CJNE A,#0FFH,T1NEXT
CLR SECHSTOF
T1NEXT: INC GEN16T0
MOV A,GEN16T0
CJNE A,#100,T1NEXT0
MOV GEN16T0,#00H
INC GEN16T1
T1NEXT0: INC SETST0
MOV A,SETST0
CJNE A,#100,T1RETI
MOV SETST0,#00H
INC SETST1
MOV A,SETST1
CJNE A,#20,T1RETI
MOV SETST1,#00H
MOV STATU,#00H
T1RETI: POP ACC
POP PSW
RETI
;3.顯示子程序
;---------DISPLAY(03)--------
DISPLAY: PUSH ACC
PUSH DPL
PUSH DPH
MOV DPTR,#T_FIGCODE
MOV A,DISNUM0
MOVC A,@A DPTR
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,DISNUM1
MOVC A,@A DPTR
MOV SBUF,A
JNB TI,$
CLR TI
POP DPH
POP DPL
POP ACC
RET
T_FIGCODE:
DB 088H,0EBH,04CH,049H
; 0 1 2 3
DB 02BH,019H,018H,0CBH
; 4 5 6 7
DB 008H,009H,00AH,038H
; 8 9 A B
DB 09CH,068H,01CH,01EH
; C D E F
DB 080H,0E3H,044H,041H
; 0. 1. 2. 3.
DB 023H,011H,010H,0C3H
; 4. 5. 6. 7.
DB 000H,001H,002H,030H
; 8. 9. A. B.
DB 094H,060H,014H,016H
; C. D. E. F.
DB 0FFH,02FH,098H,07FH
; 熄滅 # G -
DB 07CH,078H,0BCH,00AH
; c o L R
DB 029H
; Y
;4.主程序MAIN
;---------MAIN(04)-----------
MAIN: MOV R0,#01H
CLR A
CLRAM: MOV @R0,A
INC R0
CJNE R0,#80H,CLRAM
MOV R0,A
MOV SP,#SBOTM
MOV 08H,#BUFF
;MOV 09H,#BUFF
MOV SCON,#00H
MOV TMOD,#11H
MOV TL1,#0F0H
MOV TH1,#0D8H
SETB EA
SETB ET0
SETB ET1
SETB TR1
START: MOV DPTR,#T_SONGS
RYF: LCALL RYFSUP
MOV A,R7
JZ START
CJNE R7,#0FFH,SYF
JBC NEXTSF,NEXTSCL
MOV A,STATU
JNZ GONSBQ
MOV A,BUFF0
JNZ MPSQCL
LCALL PAQSCL
SJMP MQNFD
MPSQCL: LCALL PSQSCL
MQNFD: LCALL QNFDSUP
MOVPJRYF: INC DPTR
INC DPTR
SJMP RYF
NEXTSCL: LCALL CSBESTOJG
JB CSBESTOF,CALLPSCL
LCALL PAQSCL
SJMP MOVPJRYF
CALLPSCL: LCALL PSQSCL
SJMP MOVPJRYF
GONSBQ: LCALL CSDPTR
INC DPTR
INC DPTR
SJMP MOVPJRYF
SYF: CJNE R6,#0FFH,CALLPLAY
LCALL REPCLSUP
SJMP MOVPJRYF
CALLPLAY: LCALL YFDSUP
LCALL PLAY
SJMP MOVPJRYF
;5.讀音符子程序
;---------RYFSUP(05)--------
RYFSUP: CLR A
MOVC A,@A DPTR
MOV R6,A
MOV A,#01H
MOVC A,@A DPTR
MOV R7,A
RET
;6.統(tǒng)唱曲首處理
;---------PAQSCL(06)--------
PAQSCL: MOV CSN,R6
INC DPTR
INC DPTR
LCALL RYFSUP
MOV 02H,R6
MOV 03H,R7
RET
;7.存唱曲首處理
;---------PSQSCL(07)--------
PSQSCL: PUSH PSW
SETB RS0
CLR RS1
PSQC7E: CJNE R0,#7EH,PSQNEXT
PSQNEXT: JC PSQNEXT1
MOV R0,#BUFF
SJMP PSQC7E
PSQNEXT1: MOV A,@R0
JNZ PSQNEXT2
INC R0
INC R0
INC R0
SJMP PSQC7E
PSQNEXT2: MOV CSN,@R0
INC R0
MOV 02H,@R0
INC R0
MOV 03H,@R0
INC R0
POP PSW
LCALL CSDPTR
INC DPTR
INC DPTR
RET
;8.曲號閃顯子程序
;---------QNFDSUP(08)-------
QNFDSUP: PUSH ACC
MOV GEN16T0,#00H
MOV GEN16T1,#00H
QNGON: LCALL CSNSDISN
LCALL DISPLAY
MOV GENCLK,#00H
QNWAIT: MOV A,GENCLK
CJNE A,#35,QNWAIT
MOV DISNUM0,#20H
MOV DISNUM1,#20H
LCALL DISPLAY
MOV GENCLK,#00H
QNWAIT1: MOV A,GENCLK
CJNE A,#15,QNWAIT1
MOV A,GEN16T1
CJNE A,#02,QNGON
POP ACC
RET
;9.曲號送顯示寄存器
;---------CSNSDISN(09)------
CSNSDISN: MOV A,CSN
ANL A,#0FH
LCALL CSBESTOJG
JNB CSBESTOF,NADP
ADD A,#10H
NADP: MOV DISNUM0,A
MOV A,CSN
SWAP A
ANL A,#0FH
MOV DISNUM1,A
RET
;10.當(dāng)前曲是否被存儲判斷
;---------CSBESTOJG(10)-----
CSBESTOJG:PUSH ACC
PUSH PSW
MOV A,BUFF0
JZ CLRCSTOF
MOV R0,#BUFF
CSBCMPCSN:MOV A,@R0
CJNE A,CSN,CSBGSCAN
SETB CSBESTOF
SJMP CSBRET
CSBGSCAN: INC R0
INC R0
INC R0
CJNE R0,#7EH,CSBNEXT
CSBNEXT: JC CSBCMPCSN
CLRCSTOF: CLR CSBESTOF
MOV R0,#BUFF
CSBCMP0: MOV A,@R0
JZ CSBRET
INC R0
INC R0
INC R0
CJNE R0,#7EH,CSBNEXT1
CSBNEXT1: JC CSBCMP0
CSBRET: POP PSW
POP ACC
RET
;11.找當(dāng)前曲首址
;---------CSDPTR(11)--------
CSDPTR: MOV DPTR,#T_SONGS
CSDSCAN: LCALL RYFSUP
CJNE R7,#0FFH,CSDNEXT
MOV A,R6
CJNE A,CSN,CSDNEXT
SJMP CSDRET
CSDNEXT: INC DPTR
INC DPTR
SJMP CSDSCAN
CSDRET: RET
;12.重復(fù)段處理子程序
;---------REPCLSUP(12)------
REPCLSUP: MOV A,R7
ANL A,#0FH
CJNE A,#02H,CMPA3
MOV A,R7
SWAP A
ANL A,#0FH
JNZ H4CMP1
JNB REP0F,REPRET0
CLR REP0F
MOV DPL,REP0L
MOV DPH,REP0H
REPRET0: RET
H4CMP1: CJNE A,#01H,H4CMP2
JNB REP1F,REPRET
CLR REP1F
MOV DPL,REP1L
MOV DPH,REP1H
RET
H4CMP2: CJNE A,#02H,H4CMP3
JNB REP2F,REPRET
CLR REP2F
MOV DPL,REP2L
MOV DPH,REP2H
RET
H4CMP3: CJNE A,#03H,REPRET
JNB REP3F,REPRET
CLR REP3F
MOV DPL,REP3L
MOV DPH,REP3H
RET
CMPA3: CJNE A,#03H,REPRET
MOV A,R7
SWAP A
ANL A,#0FH
JNZ H4VS1
SETB REP0F
MOV REP0L,DPL
MOV REP0H,DPH
SJMP SREPHAD
H4VS1: CJNE A,#01H,H4VS2
SETB REP1F
MOV REP1L,DPL
MOV REP1H,DPH
SJMP SREPHAD
H4VS2: CJNE A,#02H,H4VS3
SETB REP2F
MOV REP2L,DPL
MOV REP2H,DPH
SJMP SREPHAD
H4VS3: CJNE A,#03H,REPRET
SETB REP3F
MOV REP3L,DPL
MOV REP3H,DPH
SREPHAD: MOV 09H,A
LCALL CSDPTR
REPGON: INC DPTR
INC DPTR
LCALL RYFSUP
CJNE R6,#0FFH,REPGON
MOV A,R7
SWAP A
ANL A,#0FH
CJNE A,09H,REPGON
REPRET: RET
;13.音符顯示子程序
;---------YFDSUP(13)--------
YFDSUP: MOV A,STATU
JNZ YFDRET
JB SECHSTOF,YFDRET
JNB CUYFD,YFSLED
XZFCLD: MOV DISNUM0,#20H
MOV DISNUM1,#20H
SJMP YFDSPLAY
YFSLED: MOV A,R6
JZ XZFCLD
ANL A,#0FH
PUSH DPL
PUSH DPH
MOV DPTR,#T_YFDCOD
MOVC A,@A DPTR
MOV DISNUM0,A
POP DPH
POP DPL
MOV A,R6
SWAP A
ANL A,#0FH
MOV DISNUM1,A
YFDSPLAY: LCALL DISPLAY
YFDRET: RET
T_YFDCOD: DB 20H ;--
DB 01H ; 1
DB 02H ; 2
DB 03H ; 3
DB 04H ; 4
DB 05H ; 5
DB 06H ; 6
DB 07H ; 7
DB 11H ;#1
DB 12H ;#2
DB 14H ;#4
DB 15H ;#5
DB 16H ;#6
;14.唱音符子程序
;---------PLAY(14)----------
PLAY: MOV A,R6
JZ PCOSPECL
PUSH DPL
PUSH DPH
MOV DPTR,#T_SD
ANL A,#0FH
MOVC A,@A DPTR
XCH A,R6
SWAP A
ANL A,#0FH
MOV B,#12
MUL AB
ADD A,R6
ADD A,R2
RL A
MOV R6,A
MOV DPTR,#T_RAN
MOVC A,@A DPTR
MOV TH0,A
MOV R5,A
MOV A,R6
INC A
MOVC A,@A DPTR
MOV TL0,A
MOV R4,A
POP DPH
POP DPL
SETB TR0
PCOSPECL: LCALL COSPECL
PJPWAIT: MOV JPCLK,#00H
PDELAY: LCALL KCXCL
JB NEXTSF,PRET
MOV A,JPCLK
CJNE A,01H,PNEXT
PNEXT: JC PDELAY
DJNZ R7,PJPWAIT
PRET: CLR TR0
RET
;---------TABSD-------------
T_SD: DB 01h ;useless
DB 01H
DB 03H
DB 05H
DB 06H
DB 08H
DB 0AH
DB 0CH
DB 02H
DB 04H
DB 07H
DB 09H
DB 0bH
;---------TABRAN------------
T_RAN: DW 0F111H ;useless
dw 0f111h ; area 0
dw 0f1e8h
dw 0f2b2h
dw 0f373h
dw 0f426h
dw 0f4eeh
dw 0f571h
dw 0f609h
dw 0f699h
dw 0f71fh
dw 0f79fh
dw 0f817h
dw 0f889h ; area 1
dw 0f8f4h
dw 0f95ah
dw 0f9b9h
dw 0fa13h
dw 0fa68h
dw 0fab9h
dw 0fb04h
dw 0fb4ch
dw 0fb90h
dw 0fbcfh
dw 0fc0ch
dw 0fc45h ;area 2
dw 0fc7ah
dw 0fcadh
dw 0fcdch
dw 0fd0ah
dw 0fd34h
dw 0fd5ch
dw 0fd82h
dw 0fda6h
dw 0fdc8h
dw 0fde8h
dw 0fe06h
dw 0fe22h ; area 3
dw 0fe3dh
dw 0fe56h
dw 0fe6eh
dw 0fe85h
dw 0fe9ah
dw 0feaeh
dw 0fec1h
dw 0fed3h
dw 0fee3h
dw 0fef4h
dw 0ff02h
dw 0ff11h ;area 4
dw 0ff1fh
dw 0ff2bh
dw 0ff37h
dw 0ff42h
dw 0ff4dh
dw 0ff57h
dw 0ff60h
dw 0ff6ah
dw 0ff72h
dw 0ff7ah
dw 0ff81h
dw 0ff89h ; 5
;15.共速處理
評論