FLAG EQU 07FH
SPEAKER EQU P1.0
mulai:
ORG 0000H
AJMP MAIN
ISR:
ORG 000BH
LCALL ACTION
RETI
ORG 0050H
MAIN:
MOV TMOD,#00010001B ;
MOV IE,#82H ;
MOV TH0,#0H;dc
MOV TL0,#00H
SETB TR0
MOV DPTR,#effect1
MOV R0,#02
LOOP1:
ACALL sound_effect
CJNE R0,#02,CARRY_ON
SJMP MAIN ;
CARRY_ON:
ACALL PLAY
SJMP LOOP1
PLAY:
CLR EA
SETB FLAG
SETB EA
RUN:
JNB FLAG,STOP
DO:
CJNE R0,#0,START
SJMP RUN
START:
MOV TH1,R2
MOV TL1,R3
SETB TR1
HERE:
JNB TF1,HERE
CLR TF1
CLR TR1
CPL SPEAKER
SJMP RUN
STOP:
CLR SPEAKER
RET
sound_effect:
CLR A
MOVC A,@A+DPTR
MOV R0,A ;pengulangan
INC DPTR
CLR A
MOVC A,@A+DPTR
MOV R1,A ;tone length
INC DPTR
CLR A
MOVC A,@A+DPTR
MOV R2,A ;tone
INC DPTR
CLR A
MOVC A,@A+DPTR
MOV R3,A
INC DPTR
RET
ACTION:
CLR TR0
CJNE R1,#0,DO2
CLR FLAG
SJMP DO3
DO2: DEC R1
DO3:
MOV TH0,#0abH ;delay/tempo
MOV TL0,#00H
SETB TR0
RET
effect1:
; R0 R1 R2 R3
DB 1,1,0feH,09cH
DB 1,1,0feH,08cH
DB 1,1,0feH,07cH
DB 1,1,0feH,06cH
DB 1,1,0feH,05cH
DB 1,1,0feH,04cH
DB 1,1,0feH,03cH
DB 1,1,0feH,02cH
DB 1,1,0feH,01cH
DB 1,1,0feH,0cH
DB 2,0,0,0
END