单片机最小系统,两位LED数码管由串口输出接两个164驱动,Lout,Rout为左右声道输出,SET,  ALT0, ALT1为三个按键,也可自己在开始的I/O定义改成你想用的I/O口;12M晶振,若用89C51则只可装下约14首歌曲,用89C52则可装下近40曲

源程序:

;   Electronic Music
;   Version 4.50
;   Copyright (c) XAJ 2001
;============================
LOUT  BIT P1. ;左声道输出
ROUT  BIT P1. ;右声道输出
SET   BIT P3. ;SET按键
ALT0  BIT P3. ;ALT0按键
ALT1  BIT P3. ;ALT1按键

;REPNUM   EQU 09H重复段编号
STATU    EQU 0AH;状态寄存器
LDYDSR   EQU 0BH;左低音度数
RDYDSR   EQU 0CH;右低音度数
LDYAR    EQU 0DH;左低音协助
RDYAR    EQU 0EH;右低音协助
JPCLK    EQU 0FH;节拍时钟
GENCLK   EQU 10H;通用时钟
SNSDCLK  EQU 11H;搜、存显示时钟
GEN16T0  EQU 12H;通用16位时钟
GEN16T1  EQU 13H;
SETST0   EQU 14H;设置状态
SETST1   EQU 15H;  定时时钟
DISNUM0  EQU 16H;显示数值
DISNUM1  EQU 17H;寄存器(2位)
CSN      EQU 18H;当前曲曲号
REP0L    EQU 19H;0号重复段地址
REP0H    EQU 1AH;
REP1L    EQU 1BH;1号重复段地址
REP1H    EQU 1CH;
REP2L    EQU 1DH;2号重复段地址
REP2H    EQU 1EH
REP3L    EQU 1FH;3号重复段地址
REP3H    EQU 23H;
COSPEEDN EQU 24H;
SPENR    EQU 25H;

LOCF     BIT 00H;左声道开关标志
ROCF     BIT 01H;右声道开关标志
SECHSTOF BIT 02H;搜索、存储标志
NEXTSF   BIT 03H;下一曲标志
CSBESTOF BIT 04H;当前曲锁存/释放
CUYFD    BIT 05H;当前音符显示
KSETF    BIT 06H;SET键按下标志
KALT0F   BIT 07H;ALT0键按下标志
KALT1F   BIT 08H;ALT1键按下标志
SPEEDF   BIT 09H;速度增/减标志
TONEF    BIT 0AH;音调增/减标志
YPBIT    BIT 0BH;音频逻辑输出
KBDISF   BIT 0CH;键盘显示标志
REP0F    BIT 0DH;0号重复段控制
REP1F    BIT 0EH;1号重复段控制
REP2F    BIT 0FH;2号重复段控制
REP3F    BIT 10H;3号重复段控制

SBOTM    EQU 25H;堆栈区(栈底)
BUFF0    EQU 43H;锁存曲数
BUFF     EQU 44H;锁存曲缓冲区
;============================

;=========BEGIN==============
          ORG   0000H
          LJMP  MAIN
;---------T0INT--------------
          ORG   000BH
          LJMP  T0INT

;---------T1INT--------------
          ORG   001BH
          LJMP  T1INT
;.音频发生器
;---------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
;.通用时钟
;---------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,#,T1NEXT0
          MOV GEN16T0,#00H
          INC GEN16T1
T1NEXT0:  INC SETST0
          MOV A,SETST0
          CJNE A,#,T1RETI
          MOV SETST0,#00H
          INC SETST1
          MOV A,SETST1
          CJNE A,#,T1RETI
          MOV SETST1,#00H
          MOV STATU,#00H
T1RETI:   POP ACC
          POP PSW
          RETI
;.显示子程序
;---------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
;
  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
;.主程序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
;.统唱曲首处理
;---------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
;.曲号闪显子程序
;---------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,#,QNWAIT
          MOV DISNUM0,#20H
          MOV DISNUM1,#20H
          LCALL DISPLAY
          MOV GENCLK,#00H
QNWAIT1:  MOV A,GENCLK
          CJNE A,#,QNWAIT1
          MOV A,GEN16T1
          CJNE A,#,QNGON
          POP ACC
          RET
;.曲号送显示寄存器
;---------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
;.当前曲是否被存储判断
;---------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
;.找当前曲首址
;---------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
;.重复段处理子程序
;---------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
;.音符显示子程序
;---------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
          DB 02H
          DB 03H
          DB 04H
          DB 05H
          DB 06H
          DB 07H
          DB 11H  ;#1
          DB 12H  ;#2
          DB 14H  ;#4
          DB 15H  ;#5
          DB 16H  ;#6
;.唱音符子程序
;---------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

          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
;.共速处理
;---------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
;.键盘查询处理
;---------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
;.KSET键是否按下查询
;---------KSET(17)----------
KSET:     SETB SET
          JB  SET,CSETRET
          MOV GENCLK,#00H
SETLOP:   MOV A,GENCLK
          CJNE A,#,SETLOP
          SETB SET
          JB  SET,CSETRET
          CLR TR0
SETWAIT:  SETB SET
          JNB SET,SETWAIT
          MOV GENCLK,#00H
SETLOP1:  MOV A,GENCLK
          CJNE A,#,SETLOP1
          SETB TR0
          SETB KSETF
          RET
CSETRET:  CLR KSETF
          RET
;.KALT0键是否按下查询
;---------KALT0(18)---------
KALT0:    SETB ALT0
          JB  ALT0,CALT0RET
          MOV GENCLK,#00H
ALT0LOP:  MOV A,GENCLK
          CJNE A,#,ALT0LOP
          SETB ALT0
          JB  ALT0,CALT0RET
          CLR TR0
ALT0WAIT: SETB ALT0
          JNB ALT0,ALT0WAIT
          MOV GENCLK,#00H
ALT0LOP1: MOV A,GENCLK
          CJNE A,#,ALT0LOP1
          SETB TR0
          SETB KALT0F
          RET
CALT0RET: CLR KALT0F
          RET
;.KALT1键是否按下查询
;---------KALT1(19)---------
KALT1:    SETB ALT1
          JB  ALT1,CALT1RET
          MOV GENCLK,#00H
ALT1LOP:  MOV A,GENCLK
          CJNE A,#,ALT1LOP
          SETB ALT1
          JB  ALT1,CALT1RET
          CLR TR0
ALT1WAIT: SETB ALT1
          JNB ALT1,ALT1WAIT
          MOV GENCLK,#00H
ALT1LOP1: MOV A,GENCLK
          CJNE A,#,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
;.速度数送显示寄存器
;---------SPENSDISN(22)----
SPENSDISN:MOV A,SPENR
          ANL A,#0FH
          MOV DISNUM0,A
          MOV A,SPENR
          SWAP A
          ANL A,#0FH
          MOV DISNUM1,A
          RET
;.速度处理
;---------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
;.音调处理
;---------TONECL(24)---------
         ;LTONE  EQU 00  ;C
          HTONE  EQU   ;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
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
;========= 乐曲表============
;---------SONGS--------------
T_SONGS:       乐曲表表首
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  ;乐曲表表尾
          END
;=========END================

注:设计者手头有近40首曲子的音乐数据(花了大量时间对简谱进行手工转换!),而每块AT89C51的4KROM种除指令外剩下空间只可放14首左右。

这里给出第一曲和第16曲《两只老虎》作一示例。

参考链接:http://www.picavr.com/news/2008-06/6458.htm

04-13 10:50