Fully functional microcontroller music program
Time:2023-06-14
Views:962
The smallest system of single chip microcomputer, two LED Nixie tube is driven by two 164 connected to the serial port output, Lout and Rout are left and right channel output, SET, ALT0 and ALT1 are three buttons, and you can also modify the I/O definition at the beginning to your I/O port; 12M crystal oscillator
If you use 89C51, you can only hold about 14 songs, while if you use 89C52, you can hold nearly 40 songs (All Rights Reserved)
source program
; Electronic Music
; Version 4.50
; Copyright (c) XAJ 2001
;============================
LOUT BIT P1.0; Left channel output
ROUT BIT P1.2; Right channel output
SET BIT P3.3; SET button
ALT 0 BIT P3.6; ALT 0 button
ALT1 BIT P3.7; ALT1 button
; REPNUM EQU 09H Repeating segment number
Status EQU 0AH; Status register
LDYDSR EQU 0BH; Left bass degree
RDYDSR EQU 0CH; Right bass degree
LDYAR EQU 0DH; Left bass assist
RDYAR EQU 0EH; Right bass assist
JPCLK EQU 0FH; Beat clock
GENCLK EQU 10H; Universal clock
SNSDCLK EQU 11H; Search and save display clock
GEN16T0 EQU 12H; Universal 16 bit clock
GEN16T1 EQU 13H;
SETST0 EQU 14H; Set Status
SETST1 EQU 15H; Timing clock
DISNUM0 EQU 16H; Display values
DISNUM1 EQU 17H; Register (2 bits)
CSN EQU 18H; Current track number
REP0L EQU 19H; Duplicate segment address 0
REPPH EQU 1AH;
REP1L EQU 1BH; Duplicate segment address number 1
REP1H EQU 1CH;
REP2L EQU 1DH; Address of duplicate segment 2
REP2H EQU 1EH
REP3L EQU 1FH; Repeated segment address number 3
REP3H EQU 23H;
COSPEEDN EQU 24H;
SPENR EQU 25H;
LOCF BIT 00H; Left channel switch sign
ROCF BIT 01H; Right channel switch sign
SECHSTOF BIT 02H; Search, Store Flag
NEXTSF BIT 03H; Next Track Flag
CSBESTOF BIT 04H; Current song lock/release CUYFD BIT 05H; Current note display
KSETF BIT 06H; SET key press flag
KALT0F BIT 07H; ALT 0 key pressed flag
KALT1F BIT 08H; ALT1 key pressed flag
SPEEDF BIT 09H; Speed increase/decrease sign
TONEF BIT 0AH; Tone increase/decrease flag
YPBIT BIT 0BH; Audio logic output
KBDISF BIT 0CH; Keyboard Display Flag
REP0F BIT 0DH; Repetitive segment control number 0
REP1F BIT 0EH; Repetitive segment control No.1
REP2F BIT 0FH; Repetitive segment control No.2
REP3F BIT 10H; Repetitive segment control number 3
SBOTM EQU 25H; Stack area (bottom of stack)
BUFF0 EQU 43H; Number of latched songs
BUFF EQU 44H; Latch Curve Buffer
;============================
;=========BEGIN==============
ORG 0000H
LJMP MAIN
;---------T0INT--------------
ORG 000BH
LJMP T0INT
;---------T1INT--------------
ORG 001BH
LJMP T1INT
; 1. Audio generator
;---------YPFSQ(01)----------
ORG 0030H
T0INT: MOV TL0,R4
MOV TH0,R5
PUSH PSW
PUSH ACC
PUSH 01H
JB LOCF,ROPER
MOV R1,#00H
MOV A,LDYAR
T0LLOP: RRC A
MOV YPBIT,C
XCH A,R1
CJNE A,LDYDSR,T0LNEXT
MOV C,YPBIT
MOV LOUT,C
INC LDYAR
; INC P0
SJMP ROPER
T0LNEXT: XCH A,R1
INC R1
SJMP T0LLOP
ROPER: JB ROCF,T0RETI
MOV R1,#00H
MOV A,RDYAR
T0RLOP: RRC A
MOV YPBIT,C
XCH A,R1
CJNE A,RDYDSR,T0RNEXT
MOV C,YPBIT
MOV ROUT,C
INC RDYAR
; INC P2
SJMP T0RETI
T0RNEXT: XCH A,R1
INC R1
SJMP T0RLOP
T0RETI: POP 01H
POP ACC
POP PSW
RETI
; 2. Universal clock
;---------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 subroutine
;---------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 program
;---------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. Reading note subroutine
;---------RYFSUP(05)--------
RYFSUP: CLR A
MOVC A,@A+DPTR
MOV R6,A
MOV A,#01H
MOVC A,@A+DPTR
MOV R7,A
RET
; 6. Handling of Singing Songs
;---------PAQSCL(06)--------
PAQSCL: MOV CSN,R6
INC DPTR
INC DPTR
LCALL RYFSUP
MOV 02H,R6
MOV 03H,R7
RET
; 7. Processing of Saving and Singing Songs
;---------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. Track number flash subroutine
;---------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. Song number sent to display register
;---------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. Whether the current song has been stored and judged
;---------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. Find the current song address
;---------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. Repeating segment processing subroutine
;---------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. Note display subroutine
;---------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. Singing note subroutine
;---------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. Co speed processing
;---------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. Keyboard Query Processing
;---------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. Whether the KSET key is pressed to query
;---------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. Is the KALT0 key pressed to query
;---------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. Whether to press the KALT1 key to query
;---------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 key processing
;---------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 key processing
;---------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. Speed data transmission display register
;---------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. Speed processing
;---------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. Tone processing
;---------TONECL(24)---------
;LTONE EQU 00 ;C
HTONE EQU 11 ;B
TONECL: JB TONEF,DNTONE
&, nbsp; 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 key processing
;---------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
CASE1: CJNE A,#01H,CASE2
INC RDYDSR
MOV A,RDYDSR
CJNE A,#04H,RDYDSL4
MOV RDYDSR,#00H
RDYDSL4: MOV DISNUM0,RDYDSR
MOV DISNUM1,#27H
RET
CASE2: CJNE A,#02H,CASE3
MOV A,COSPEEDN
JZ KA1NEXT5
DEC COSPEEDN
KA1NEXT5: MOV SPENR,COSPEEDN
LCALL SPENSDISN
RET
CASE3: CJNE A,#03H,CASE4
SETB SPEEDF
LCALL SPEEDCL
RET
CASE4: CJNE A,#04H,CASE5
SETB TONEF
LCALL TONECL
RET
CASE5: CJNE A,#05H,CASE6
CPL ROCF
JNB ROCF,KA1NEXT3
MOV DISNUM0,#24H
SJMP KA1NEXT4
KA1NEXT3: MOV DISNUM0,#25H
KA1NEXT4: MOV DISNUM1,#27H
RET
CASE6: CJNE A,#06H,KA1RET
MOV DISNUM0,#23H
MOV DISNUM1,#06H
KA1RET: RET
========= Music Table============
;---------SONGS--------------
T_SONGS: Music Table First
dw 01ffh,;song1:xiao la ba...
dw 0b05h,
dw 2504h,
dw 2604h,
dw 2506h,
dw 0002h,
dw 2504h,
dw 2604h,
dw 2506h,
dw 0002h,
dw 2504h,
dw 2604h,
dw 2504h,
dw 2304h,
dw 2204h,
dw 2104h,
dw 2206h,
DW 16FFH;SONG16:Liang Zhi Lao Hu
DW 0715H
DW 0FF21H ;REP21
DW 0FF01H ;REP01
DW 2102H
DW 2202H
DW 2302H
DW 2102H
DW 0FF02H ;REP02
DW 0FF03H ;REP03
DW 2302H
DW 2402H
DW 2504H
DW 2302H
DW 2402H
DW 2504H
DW 0FF11H ;REP11
DW 2501H
DW 2601H
DW 2501H
DW 2401H
DW 2302H
DW 2102H
DW 0FF12H ;REP12
DW 0FF13H ;REP13
DW 2202H
DW 1502H
DW 2104H
DW 2202H
DW 1502H
DW 2104H
DW 0FF22H ;REP22
DW 0FF23H ;REP23
DW 0000H ;Music Table Ending
END
;=========END================
Note: The designer has nearly 40 pieces of music data on hand (spent a lot of time manually converting the notation!), while each AT89C51 4KROM has only about 14 pieces of space left except for instructions.
Here is an example of the first and 16th songs "Two Tigers".
Here is an example of the first and 16th songs "Two Tigers".