按大写字母“B”,唱乐曲“太湖船”
按大写字母“C”,唱乐曲“祝福歌”
按"X"脊搜键哗没,退出
DATA SEGMENT PARA 'DATA'
INFO1 DB 0DH,0AH,'WELCOME YOU TO COME HERE!$'
INFO2 DB 0DH,0AH,'this is a music program!$'
INFO3 DB 0DH,0AH,'please select!$'
INFO4 DB 0DH,0AH,'INPUT ERROR!$'
INFO5 DB 0DH,0AH,'PLEASE INPUT AGAIN!$'
MUSLIST DB 0DH,0AH,'A MUSIC1'
DB 0DH,0AH,'B MUSIC2'
DB 0DH,0AH,'C MUSIC3'
DB 0DH,0AH,'Q EXIT'
db 0dh,0ah,'$'
MUS_FREG1 DW 330,294,262,294,3 DUP (330)
DW 3 DUP (294),330,392,392
DW 330,294,262,294,4 DUP (330)
DW 294,294,330,294,262,-1
MUS_TIME1 DW 6 DUP (25*8),50*8
DW 2 DUP (25*8,25*8,50*8)
DW 12 DUP (25*8),100*8
MUS_FREG2 DW 330,392,330,294,330,392,330,294,330
DW 330,392,330,294,262,294,330,392,294
DW 262,262,220,196,196,220,262,294,332,262,-1
MUS_TIME2 DW 3 DUP(50),25,25,50,25,25,100
DW 2 DUP(50,50,25,25),100
DW 3 DUP(50,25,25),100
MUS_FREG3 DW 262,262,294,262,349
DW 330,262,262,294,262
DW 392,349,262,262,523
DW 440,349,262,262,466
DW 466,440,262,392,349,-1
MUS_TIME3 DW 50,50,100,100,100
DW 100,100,50,50,100,100
DW 100,100,100,50,50,100
DW 100,100,100,100,100,50
DW 50,100,100,100,100,100
DATA ENDS
STACK SEGMENT PARA STACK 'STACK'
DB 200 DUP ('STACK')
STACK ENDS
CODE SEGMENT
ASSUME DS:DATA,SS:STACK,CS:CODE
MAIN PROC FAR
MOV AX,DATA
MOV DS,AX
MOV aH, 0
MOV AL,4
INT 10H
MOV AH,0BH
MOV BH,0
MOV BL,4
INT 10H
MOV AH,0BH
MOV BH,01H
MOV BL,00
INT 10H
*****定义一个宏*****
SHOW MACRO b
LEA DX,b
MOV AH,9
INT 21H
ENDM
**********************
show INFO1
show INFO2
show INFO3
show MUSLIST
INPUT:MOV AH,01H
INT 21H
CMP AL,'Q'
JZ retu
CMP AL,'A'
JNZ B0
CALL MUSIC1
JMP EXIT1
B0: CMP AL,'B'
JNZ C0
CALL MUSIC2
JMP EXIT1
C0: CMP AL,'C'
JNZ exit
CALL MUSIC3
EXIT1:show INFO5
JMP INPUT
EXIT:
call clear
show INFO4
show INFO5
show INFO1
show INFO2
show INFO3
show MUSLIST
jmp input
RETU: MOV AH,4CH
INT 21H
MAIN ENDP
MUSIC1PROC NEAR
PUSH DS
SUB AX,AX
PUSH AX
LEA SI,MUS_FREG1
LEA BP,DS:MUS_TIME1
FREG1: MOV DI,[SI]
CMP DI,-1
JE END_MUS1
MOV DX,DS:[BP]
MOV BX,1400
CALL GENSOUND
ADD SI,2
ADD BP,2
JMP FREG1
END_MUS1:
RET
MUSIC1ENDP
GENSOUND PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
MOV AL,0B6H
OUT 43H,AL
MOV DX,12H
MOV AX,533H*896
DIV DI
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
IN AL,61H
MOV AH,AL
OR AL,3
OUT 61H,AL
WAIT1:MOV CX,8FF0H
DELAY1: LOOP DELAY1
DEC BX
JNZ WAIT1
MOV AL,AH
OUT 61H,AL
POP DI
POP DX
POP CX
POP BX
POP AX
RET
GENSOUND ENDP
MUSIC2PROC NEAR
PUSH DS
SUB AX,AX
PUSH AX
LEA SI,MUS_FREG2
LEA BP,DS:MUS_TIME2
FREG2:MOV DI,[SI]
CMP DI,-1
JE END_MUS2
MOV DX,DS:[BP]
MOV BX,1400
CALL GENSOUND
ADD SI,2
ADD BP,2
JMP FREG1
END_MUS2:
RET
MUSIC2ENDP
MUSIC3PROC NEAR
PUSH DS
SUB AX,AX
PUSH AX
LEA SI,MUS_FREG3
LEA BP,DS:MUS_TIME3
FREG3:MOV DI,[SI]
CMP DI,-1
JE END_MUS3
MOV DX,DS:[BP]
MOV BX,1400
CALL GENSOUND
ADD SI,2
ADD BP,2
JMP FREG1
END_MUS3:
RET
MUSIC3ENDP
clear proc near
push ax
push bx
push cx
push dx
mov ah,6
mov al,0
mov ch,0
mov cl,0
mov dh,24
mov dl,79
mov bh,7
int 10h
pop dx
pop cx
pop bx
pop ax
ret
clear endp
CODE ENDS
END MAIN
OUT BIT P2.3 //该引脚接蜂鸣器ORG 0000H
LJMP START
ORG 000BH
INC 20H 中断服务,中断计数器加1
MOV TH0,#0D8H
MOV TL0,#0EFH 12M晶振,形成首昌早10毫秒中断
RETI
START:
MOV SP,#50H
MOV TH0,#0D8H
MOV TL0,#0EFH
MOV TMOD,#01H
MOV IE,#82H
MUSIC0:
NOP
MOV DPTR,#DAT 表头地址送DPTR
MOV 20H,#00H 中断计数器清0
MOV B,#00H 表序号清0
MUSIC1:
NOP
CLR A
MOVC A,@A+DPTR 查表取代码
JZ END0 是00H,则结束
CJNE A,#0FFH,MUSIC5
LJMP MUSIC3
MUSIC5:
NOP
MOV R6,A
INC DPTR
MOV A,B
MOVC A,@A+DPTR 取节拍代码送R7
MOV R7,A
SETB TR0 启动计数
MUSIC2:
NOP
CPL OUT
MOV A,R6
MOV R3,A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 中断计数器(20H)=R7否?
不等,则继续者雀循环
MOV 20H,#00H 等于,则取下一代码
INC DPTR
INC B
LJMP MUSIC1
MUSIC3:
NOP
CLR TR0 休止100毫秒
MOV R2,#0DH
MUSIC4:
NOP
MOV R3,#0FFH
LCALL DEL
DJNZ R2,MUSIC4
INC DPTR
LJMP MUSIC1
END0:
NOP
MOV R2,#64H 歌曲迅弯结束,延时1秒后继续
MUSIC6:
MOV R3,#00H
LCALL DEL
DJNZ R2,MUSIC6
LJMP MUSIC0
DEL:
NOP
DEL3:
MOV R4,#02H
DEL4:
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
NOP
DAT:
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)