门铃源代码分享
时间:10-02
整理:3721RD
点击:
(附)源程序如下:
ORG 00H ;初始化程序
JMP START
ORG 0BH
LJMP TIM0
START:MOV TMOD,#00000001B ;主程序
MOV IE,#10000010B
JB P3.5, $
CALL DELAY1
JNB P3.5, $
MOV 31H,#00
START0:
MOV 30H,#SONG
NEXT: MOV A,30H
MOV DPTR,# TABLE
MOVC A,@A+DPTR
MOV R2,A
JZ END0
ANL A,#0FH
MOV R5,A
MOV A,R2
SWAP A
ANL A,#0FH
JNZ SING
CLR TR0
JMP D1
SING: DEC A
MOV 22H,A
RL A
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV TH0,A
MOV 21H,A
MOV A,22H
RL A
INC A
MOVC A,@A+DPTR
MOV TL0,A
MOV 20H,A
SETB TR0
D1: CALL DELAY
INC 30H
JMP NEXT
END0: CLR TR0
MOV A,31H
XRL A,#00H
JNZ END1
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG1
JMP NEXT
END1:
MOV A,31H
XRL A,#01H
JNZ END2
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG2
JMP NEXT
END2:
MOV A,31H
XRL A,#02H
JNZ END3
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG3
JMP NEXT
END3:
MOV A,31H
XRL A,#03H
JNZ END4
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG4
JMP NEXT
END4:
MOV A,31H
XRL A,#04H
JNZ END5
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG5
JMP NEXT
END5:
JMP START
TIM0: PUSH ACC ;定时器T0子程序
PUSH PSW
SETB RS0
CLR RS1
MOV TL0,20H
MOV TH0,21H
CPL P1.0
POP PSW
POP ACC
RETI
DELAY: ;延时子程序
MOV R7,#02
D2: MOV R4,#125
D3: MOV R3,#248
DJNZ R3,$
DJNZ R4,D3
DJNZ R7,D2
DJNZ R5,DELAY
RET
DELAY1:
MOV R4,#20
D4: MOV R3,#248
DJNZ R3,$
DJNZ R4,D4
RET
ORG 300H
;定时常数T值表
TABLE:
DW 64260,64400,64524,64580
DW 64684,64777,64820,64898
DW 64968,65030,65058,65110
DW 65157,65178,65217
;音符节拍码数据表
SONG: ;生日快乐
;1
DB 82H,01H,81H,94H,84H
DB 0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H
DB 0C4H,0B4H,04H
;2
DB 82H,01H,81H,0F4H,0D4H
DB 0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H
DB 0C4H,0B4H,04H
DB 00H
SONG1: ;两只老虎
;1
DB 44H,54H,64H,44H
DB 44H,54H,64H,44H
DB 64H,74H,88H
DB 64H,74H,88H
;2
DB 82H,92H,82H,72H,64H,44H
DB 82H,92H,82H,72H,64H,44H
DB 44H,84H,48H
DB 44H,14H,48H
DB 00H
SONG2: ;三只小猫
;1
DB 62H,82H,82H,62H,98H
DB 92H,0B2H,0B2H,82H,98H
DB 62H,82H,82H,52H,68H
DB 92H,0B2H,0B2H,82H,98H
;2
DB 62H,82H,82H,62H,92H,92H,94H
DB 92H,0B2H,0B2H,92H,84H,94H
DB 0B8H,0B4H,04H
DB 00H
SONG3: ;哈巴狗
;1
DB 42H,42H,42H,52H,64H,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H
;2
DB 42H,42H,42H,52H,64H,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H
DB 00H
SONG4: ;不倒翁
;1
DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44H
DB 62H,82H,42H,62H,58H
;2
DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44H
DB 52H,42H,52H,62H,48H
DB 00H
SONG5: ;妹妹背着洋娃娃
;1
DB 84H,02H,82H,64H,54H
DB 64H,54H,48H
DB 64H,02H,52H,44H,24H
DB 14H,24H,18H
;2
DB 24H,02H,22H,42H,24H
DB 44H,54H,68H
DB 54H,02H,52H,84H,84H
DB 54H,64H,48H
DB 00H
END
ORG 00H ;初始化程序
JMP START
ORG 0BH
LJMP TIM0
START:MOV TMOD,#00000001B ;主程序
MOV IE,#10000010B
JB P3.5, $
CALL DELAY1
JNB P3.5, $
MOV 31H,#00
START0:
MOV 30H,#SONG
NEXT: MOV A,30H
MOV DPTR,# TABLE
MOVC A,@A+DPTR
MOV R2,A
JZ END0
ANL A,#0FH
MOV R5,A
MOV A,R2
SWAP A
ANL A,#0FH
JNZ SING
CLR TR0
JMP D1
SING: DEC A
MOV 22H,A
RL A
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV TH0,A
MOV 21H,A
MOV A,22H
RL A
INC A
MOVC A,@A+DPTR
MOV TL0,A
MOV 20H,A
SETB TR0
D1: CALL DELAY
INC 30H
JMP NEXT
END0: CLR TR0
MOV A,31H
XRL A,#00H
JNZ END1
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG1
JMP NEXT
END1:
MOV A,31H
XRL A,#01H
JNZ END2
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG2
JMP NEXT
END2:
MOV A,31H
XRL A,#02H
JNZ END3
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG3
JMP NEXT
END3:
MOV A,31H
XRL A,#03H
JNZ END4
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG4
JMP NEXT
END4:
MOV A,31H
XRL A,#04H
JNZ END5
JB P3.5,$
CALL DELAY1
JNB P3.5,$
INC 31H
MOV 30H,#SONG5
JMP NEXT
END5:
JMP START
TIM0: PUSH ACC ;定时器T0子程序
PUSH PSW
SETB RS0
CLR RS1
MOV TL0,20H
MOV TH0,21H
CPL P1.0
POP PSW
POP ACC
RETI
DELAY: ;延时子程序
MOV R7,#02
D2: MOV R4,#125
D3: MOV R3,#248
DJNZ R3,$
DJNZ R4,D3
DJNZ R7,D2
DJNZ R5,DELAY
RET
DELAY1:
MOV R4,#20
D4: MOV R3,#248
DJNZ R3,$
DJNZ R4,D4
RET
ORG 300H
;定时常数T值表
TABLE:
DW 64260,64400,64524,64580
DW 64684,64777,64820,64898
DW 64968,65030,65058,65110
DW 65157,65178,65217
;音符节拍码数据表
SONG: ;生日快乐
;1
DB 82H,01H,81H,94H,84H
DB 0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H
DB 0C4H,0B4H,04H
;2
DB 82H,01H,81H,0F4H,0D4H
DB 0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H
DB 0C4H,0B4H,04H
DB 00H
SONG1: ;两只老虎
;1
DB 44H,54H,64H,44H
DB 44H,54H,64H,44H
DB 64H,74H,88H
DB 64H,74H,88H
;2
DB 82H,92H,82H,72H,64H,44H
DB 82H,92H,82H,72H,64H,44H
DB 44H,84H,48H
DB 44H,14H,48H
DB 00H
SONG2: ;三只小猫
;1
DB 62H,82H,82H,62H,98H
DB 92H,0B2H,0B2H,82H,98H
DB 62H,82H,82H,52H,68H
DB 92H,0B2H,0B2H,82H,98H
;2
DB 62H,82H,82H,62H,92H,92H,94H
DB 92H,0B2H,0B2H,92H,84H,94H
DB 0B8H,0B4H,04H
DB 00H
SONG3: ;哈巴狗
;1
DB 42H,42H,42H,52H,64H,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H
;2
DB 42H,42H,42H,52H,64H,04H
DB 62H,62H,62H,72H,84H,04H
DB 92H,92H,82H,72H,64H,04H
DB 82H,82H,52H,62H,44H,04H
DB 00H
SONG4: ;不倒翁
;1
DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44H
DB 62H,82H,42H,62H,58H
;2
DB 84H,94H,88H
DB 64H,54H,68H
DB 84H,64H,54H,44H
DB 52H,42H,52H,62H,48H
DB 00H
SONG5: ;妹妹背着洋娃娃
;1
DB 84H,02H,82H,64H,54H
DB 64H,54H,48H
DB 64H,02H,52H,44H,24H
DB 14H,24H,18H
;2
DB 24H,02H,22H,42H,24H
DB 44H,54H,68H
DB 54H,02H,52H,84H,84H
DB 54H,64H,48H
DB 00H
END