BELL BIT P1.3 LCOUNT1 DATA 30H ;循环次数1 LCOUNT2 DATA 31H ;循环次数2
ORG 0000H LJMP MAIN ORG 0100H
MAIN: MOV SP,#80H CALL MUSIC JMP MAIN MUSIC: MOV R7,#0 SLONG:MOV DPTR,#SOUND_LONG MOV A,R7 MOVC A,@A+DPTR MOV LCOUNT1,A ;送发音的长短到LONGT1 MOV A,R7 MOV DPTR,#SOUND_TONE MOVC A,@A+DPTR MOV LCOUNT2,A ;送音符的周期到LCOUNT2/即音的高低 MOV R4,LCOUNT1 ;循环 音长 LONG: MOV R6,#12 ;循环节拍 MUSI: MOV R5,LCOUNT2 ;产生音调所需要的方波 MUSI1:CLR BELL ;开蜂鸣器 DJNZ R5,MUSI1 ;开蜂鸣器 音调次后退出 MOV R5,LCOUNT2 MUSI2:SETB BELL ;关蜂鸣器 DJNZ R5,MUSI2 ; 关蜂鸣器音调次后退出 DJNZ R6,MUSI DJNZ R4,LONG PUSH 7 PUSH 6 LONGS:CALL DELAY POP 6 POP 7 INC R7 CJNE R7,#40,SLONG RET
DELAY:;延时10ms MOV R7,#90H; D1: MOV R6,#0A0H; D0: NOP DJNZ R6,D0 DJNZ R7,D1 RET SOUND_LONG: ;MUSIC中每一个音符的长度 DB 60,30,30,60,30,30,60,30,120,60 DB 30,30,60,30,30,30,30,30,120,60 DB 30,30,30,30,30,30,30,30,60,30 DB 120,60,60,60,30,30,30,60,30,120 SOUND_TONE: ;MUSIC中每一个音符的音调 DB 142,159,189,142,159,189,142,142,159,142 DB 142,159,189,142,159,189,212,212,239,212 DB 189,189,159,142,120,142,159,189,189,159 DB 239,189,189,189,189,189,142,142,159,142 END |