單片機(jī)音樂(lè)程序
;---------COSPECL(15)-------
COSPECL: MOV R1,03H
MOV A,COSPEEDN
JZ COSPRET
PUSH COSPEEDN
MOV A,R1
COSPEGON: MOV B,#08H
MUL AB
CLR C
SUBB A,R1
JNC COSPNEXT
DEC B
COSPNEXT: MOV R6,#03H
DIV8: CLR C
XCH A,B
RRC A
XCH A,B
RRC A
DJNZ R6,DIV8
MOV R1,A
DJNZ COSPEEDN,COSPEGON
POP COSPEEDN
MOV A,R1
JNZ COSPRET
MOV R1,#01H
COSPRET: RET
;16.鍵盤(pán)查詢(xún)處理
;---------KCXCL(16)---------
KCXCL: LCALL KSET
LCALL KALT0
LCALL KALT1
JNB KSETF,KNEXT0
LCALL KSETCL
KSETSTC: MOV SETST0,#00H
MOV SETST1,#00H
SETB KBDISF
SJMP KDIS
KNEXT0: JNB KALT0F,KNEXT1
LCALL KALT0CL
SJMP KSETSTC
KNEXT1: JNB KALT1F,KDIS
LCALL KALT1CL
SJMP KSETSTC
KDIS: MOV A,STATU
JNZ KSSNSD
JNB SECHSTOF,KRET
KSSNSD: JNB KBDISF,KRET
CLR KBDISF
LCALL DISPLAY
KRET: RET
;17.KSET鍵是否按下查詢(xún)
;---------KSET(17)----------
KSET: SETB SET
JB SET,CSETRET
MOV GENCLK,#00H
SETLOP: MOV A,GENCLK
CJNE A,#02,SETLOP
SETB SET
JB SET,CSETRET
CLR TR0
SETWAIT: SETB SET
JNB SET,SETWAIT
MOV GENCLK,#00H
SETLOP1: MOV A,GENCLK
CJNE A,#02,SETLOP1
SETB TR0
SETB KSETF
RET
CSETRET: CLR KSETF
RET
;18.KALT0鍵是否按下查詢(xún)
;---------KALT0(18)---------
KALT0: SETB ALT0
JB ALT0,CALT0RET
MOV GENCLK,#00H
ALT0LOP: MOV A,GENCLK
CJNE A,#02,ALT0LOP
SETB ALT0
JB ALT0,CALT0RET
CLR TR0
ALT0WAIT: SETB ALT0
JNB ALT0,ALT0WAIT
MOV GENCLK,#00H
ALT0LOP1: MOV A,GENCLK
CJNE A,#02,ALT0LOP1
SETB TR0
SETB KALT0F
RET
CALT0RET: CLR KALT0F
RET
;19.KALT1鍵是否按下查詢(xún)
;---------KALT1(19)---------
KALT1: SETB ALT1
JB ALT1,CALT1RET
MOV GENCLK,#00H
ALT1LOP: MOV A,GENCLK
CJNE A,#02,ALT1LOP
SETB ALT1
JB ALT1,CALT1RET
CLR TR0
ALT1WAIT: SETB ALT1
JNB ALT1,ALT1WAIT
MOV GENCLK,#00H
ALT1LOP1: MOV A,GENCLK
CJNE A,#02,ALT1LOP1
SETB TR0
SETB KALT1F
RET
CALT1RET: CLR KALT1F
RET
;20.SET鍵處理
;---------KSETCL(20)--------
KSETCL: INC STATU
MOV A,STATU
CJNE A,#07H,STATUDIS
MOV STATU,#00H
STATUDIS: MOV DISNUM0,#23H
MOV DISNUM1,STATU
RET
;21.KALT0鍵處理
;---------KALT0CL(21)-------
KALT0CL: MOV A,STATU
JNZ CASEB1
KA0S0GO: INC DPTR
INC DPTR
LCALL RYFSUP
MOV A,R7
JNZ EQUFF
MOV DPTR,#T_SONGS
SJMP KA0NEXT
EQUFF: INC A
JNZ KA0S0GO
KA0NEXT: LCALL RYFSUP
MOV CSN,R6
LCALL CSNSDISN
MOV A,DPL
CLR C
SUBB A,#02H
JNC KA0NEXT1
DEC DPH
KA0NEXT1: MOV DPL,A
CLR REP0F
CLR REP1F
CLR REP2F
CLR REP3F
SETB NEXTSF
SETB SECHSTOF
RET
CASEB1: CJNE A,#01H,CASEB2
INC LDYDSR
MOV A,LDYDSR
CJNE A,#04H,LDYDSL4
MOV LDYDSR,#00H
LDYDSL4: MOV DISNUM0,LDYDSR
MOV DISNUM1,#26H
RET
HCOSPEEDN EQU 12H
CASEB2: CJNE A,#02H,CASEB3
MOV A,COSPEEDN
CJNE A,#HCOSPEEDN,KA0NEXT4
KA0NEXT4: JNC KA0NEXT5
INC COSPEEDN
KA0NEXT5: MOV SPENR,COSPEEDN
LCALL SPENSDISN
RET
CASEB3: CJNE A,#03H,CASEB4
CLR SPEEDF
LCALL SPEEDCL
RET
CASEB4: CJNE A,#04H,CASEB5
CLR TONEF
LCALL TONECL
RET
CASEB5: CJNE A,#05H,CASEB6
CPL LOCF
JNB LOCF,KA0NEXT2
MOV DISNUM0,#24H
SJMP KA0NEXT3
KA0NEXT2: MOV DISNUM0,#25H
KA0NEXT3: MOV DISNUM1,#26H
RET
CASEB6: CJNE A,#06H,KA0RET
CPL CUYFD
JNB CUYFD,KA0NEXT6
MOV DISNUM0,#24H
SJMP KA0NEXT7
KA0NEXT6: MOV DISNUM0,#25H
KA0NEXT7: MOV DISNUM1,#28H
KA0RET: RET
;22.速度數(shù)送顯示寄存器
;---------SPENSDISN(22)----
SPENSDISN:MOV A,SPENR
ANL A,#0FH
MOV DISNUM0,A
MOV A,SPENR
SWAP A
ANL A,#0FH
MOV DISNUM1,A
RET
;23.速度處理
;---------SPEEDCL(23)------
HSPEED EQU 02H;
LSPEED EQU 50H;
SPEEDCL: JB SPEEDF,DNSPEED
CJNE R3,#HSPEED,SCLNEXT
SCLNEXT: JC SCLNEXT1
DEC R3
SJMP SCLNEXT1
DNSPEED:
CJNE R3,#LSPEED,SCLNEXT2
SCLNEXT2: JNC SCLNEXT1
INC R3
SCLNEXT1: LCALL CSBESTOJG
JNB CSBESTOF,SCLNEXT3
INC R0
INC R0
MOV @R0,03H
SCLNEXT3: LCALL COSPECL
MOV SPENR,R1
LCALL SPENSDISN
RET
;24.音調(diào)處理
;---------TONECL(24)---------
;LTONE EQU 00 ;C
HTONE EQU 11 ;B
TONECL: JB TONEF,DNTONE
CJNE R2,#HTONE,TCLNEXT0
TCLNEXT0: JNC TCLNEXT
INC R2
SJMP TCLNEXT
DNTONE: MOV A,R2
JZ TCLNEXT
DEC R2
TCLNEXT: LCALL CSBESTOJG
JNB CSBESTOF,TCLNEXT1
INC R0
MOV @R0,02H
TCLNEXT1: PUSH DPL
PUSH DPH
MOV DPTR,#T_TONDISC
MOV A,R2
RL A
MOVC A,@A DPTR
MOV DISNUM1,A
MOV A,R2
RL A
INC A
MOVC A,@A DPTR
MOV DISNUM0,A
POP DPH
POP DPL
RET
T_TONDISC:DW 200CH ; C
DW 210CH ;#C
DW 200DH ; D
DW 210DH ;#D
DW 200EH ; E
DW 200FH ; F
DW 210FH ;#F
DW 2022H ; G
DW 2122H ;#G
DW 200AH ; A
DW 210AH ;#A
DW 200BH ; B
;25.KALT1鍵處理
;---------KALT1CL(25)--------
KALT1CL: MOV A,STATU
JNZ CASE1
LCALL CSBESTOJG
JNB CSBESTOF,KA1NEXT
MOV @R0,#00H
DEC BUFF0
SJMP KA1NEXT2
KA1NEXT: CJNE R0,#7EH,KA1NEXT1
KA1NEXT1: JNC KA1NEXT2
MOV @R0,CSN
INC R0
MOV @R0,02H
INC R0
MOV @R0,03H
INC BUFF0
KA1NEXT2: LCALL CSNSDISN
SETB SECHSTOF
RET
評(píng)論