;音乐生日快乐的播放
numtim equ 20h
EQUei equ 21h
EQUwei equ 22h
EQUnled equ 23h
EQU 000hORGp startJMPg 00bh
jORGtim0
oJMP100h
ORGart:; JB P3.7,$ ;检测播放按键是否按下
mov tmod,#00000001b
MOV mov ie,#10000010b
MOV mov numtim,#01h
startMOVov 30h,#00h
nextMOVv a,30h
mov MOVr,#table
MOVovc a,@a+dptr
mov r2,a
jz eMOV
anl aJZ0fh
mov r5,a
mov aMOV
swap MOV anl a,#0fh
jnz sing
clr tJNZ
jmp d1
sing: dec aJMP mov 22h,DEC rl aMOV mov dptr,#table1
MOVmovc a,@a+dptr
mov th0,a
mov MOV,a
mov MOV2h
rl aMOV inc a
movc a,@INCptr
mov tl0,a
mov MOV,a
setbMOV0
d1:lcall delay
inc 30h
jmp neINC
end0:clr JMP
jmp start0
tim0:puJMPacc
pushPUSH
mov PUSH2PSW
MOV th0,21h
MOV p1.6 ;由该口输出音频数据
pop psw
pop acc
POPrPSW
dPOPy: mov r7,#02h
d2: mov r4,#1MOV
d3: mov r3,#MOV
djnz r3,MOV djnz r4,d3
djnz r7,d2
djnz r5,delay
ret
table1: RET ;音乐码表
dw 64260,64400,64524,64580
DW dw 64684,64777,64820,64898
DW dw 64968,65030,65058,65110
DW dw 65157,65178,65217
table:dDW82h,01h,81h,94h,84h
DB 0b4h,0a4h,04h
db 82hDB1h,81h,94h,84h
DB 0c4h,0b4h,04h
db 8DB,01h,81h,0f4h,0d4h
DBdb 0b4h,0a4h,94h
db 0e2DB01h,0e1h,0d4h,0b4h
DB db 0c4h,0b4h,04h
db 8DB,01h,81h,94h,84h
DB 0b4h,0a4h,04h
db 82hDB1h,81h,94h,84h
DB 0c4h,0b4h,04h
db 8DB,01h,81h,0f4h,0d4h
DBdb 0b4h,0a4h,94h
db 0e2DB01h,0e1h,0d4h,0b4h
DB db 0c4h,0b4h,04h
db 00DB
TABLE2:DB 0C0H,0F9H,DB4H,0B0H,99H,92H,8DB,0F8H,80H,90H
end
END
我只有生日快乐的程序,希望对你有帮助,从我这个程序你了解了原理,你就可以随意搞了,玩熟悉了就简单了!