振动传感器拾取到振动信号后经Q1放大给IC1,JS83就是一个PIC12C508单片机,它的6脚按照程序输出所需要的音调波形,经Q2推动升压变压器升压,驱动压电蜂鸣器发声。
原理图:
下面是用PIC16C54做的测试程序,程序按照音调波形图编制。
PIC54 EQU 1FFH
PIC57 EQU 7FFH
SUB EQU 0
PORTA EQU 05H
RA EQU 05H
PORTB EQU 06H
RB EQU 06H
STATUS EQU 03H
PA2 EQU 7
PA1 EQU 6
PA0 EQU 5
TO EQU 4
PD EQU 3
Z EQU 2
DC EQU 1
C EQU 0
DEL200USCount EQU 07H
DEL200US EQU 08H
DEL1SCount EQU 09H
FLAG EQU 0AH
THREE EQU 0BH
KAIJIDEL EQU 0CH
Buf1 EQU 0DH
Buf2 EQU 0EH
DEL10SBuf1 EQU 0FH
DEL10SBuf2 EQU 10H
LXXCount EQU 11H
LXXBuf1 EQU 12H
LXXEndBuf EQU 13H
LXXCount1 EQU 14H
TEMP EQU 1EH
DEL20USCount EQU 1FH
PortAStatus EQU 00H
PortBStatus EQU 01H
;RB.0=振动信号 1
;RB.1=OUT 0
;*******************************************
ORG SUB
MAIN:
GOTO BEGIN
;*******************************************
DELAY1S: ;延时60MS
MOVLW 07H
OPTION
CLRF 1
WAIT:
CLRWDT
MOVF 1,0
XORLW 0EBH
BTFSS STATUS,Z
GOTO WAIT
RETLW 00H
;*******************************************
DELAY: ;发3声控制
MOVLW 3 ;3
MOVWF DEL200US
DELAY1:
MOVLW 200 ;200
MOVWF DEL1SCount
LOOP_100MS:
CLRWDT
BSF RB,1
CALL DELAY200us
BCF RB,1
CALL DELAY200us
DECFSZ DEL1SCount,1
GOTO LOOP_100MS
DECFSZ DEL200US,1
GOTO DELAY1
RETLW 00H
;*******************************************
DELAY_LXX: ;连续发声控制
MOVLW 8 ;8
MOVWF DEL200US
MOVLW 21 ;21
MOVWF TEMP
DELAY11:
MOVLW 60 ;60
MOVWF DEL1SCount
LOOP:
CLRWDT
BSF RB,1
CALL DELAY200us
BCF RB,1
MOVF TEMP,0
MOVWF LXXBuf1
LOOP1:
CALL DELAY20US
DECFSZ LXXBuf1,1
GOTO LOOP1
DECFSZ DEL1SCount,1
GOTO LOOP
DECF TEMP,1
MOVF TEMP,0
MOVWF LXXBuf1
DECFSZ DEL200US,1
GOTO DELAY11
RETLW 00H
;*******************************************
DELAY200us: ;延时200us
MOVLW 50 ;50
MOVWF DEL200USCount
DELAY200us1:
NOP
DECFSZ DEL200USCount,1
GOTO DELAY200us1
RETLW 00H
;*******************************************
DELAY20us: ;延时20us
MOVLW 5 ;5
MOVWF DEL20usCount
DELAY20us1:
DECFSZ DEL20usCount,1
GOTO DELAY20us1
RETLW 00H
;*******************************************
TestZD: ;检测振动信号
MOVLW 40H ;40
MOVWF Buf1
CLRF Buf2
TestZD1:
CLRWDT
BTFSS RB,0 ;ZD input
INCF Buf2,1
DECFSZ Buf1,1
GOTO TestZD1
BCF Flag,0
MOVLW 30H ;30
SUBWF Buf2,1
BTFSS STATUS,C
BSF Flag,0 ;Flag.0=1有振动
RETLW 00H
;*******************************************
BEGIN:
MOVLW PortAStatus
TRIS RA
MOVLW PortBStatus
TRIS RB
MOVLW 07H ;预分频器分频比1/256
OPTION
BCF RB,1
;BTFSS STATUS,TO ;看门狗复位转,上电复位继续
;GOTO MAINLOOP
INIT: ;初始化
CLRF FLAG ;清标志寄存器
KAIJI_1S:
CALL DELAY ;开机响1秒
;///////////////////////////////////////////
MOVLW 10H ;开机延时1S,等待单片机稳定
MOVWF KAIJIDEL
KAIJI:
CALL DELAY1S
DECFSZ KAIJIDEL,1
GOTO KAIJI
;*******************************************
MAINLOOP:
MOVLW PortAStatus
TRIS RA
MOVLW PortBStatus
TRIS RB
MOVLW 07H ;预分频器分频比1/256
OPTION
CLRWDT
BCF RB,1
;SLEEP
BTFSC FLAG,7
GOTO LXX_CONTIUE
MAINLOOP1:
CALL TESTZD ;检测是否有振动
BTFSS FLAG,0
GOTO MAINLOOP
BSF FLAG,7 ;第一次触发标志,FLAG=1
MOVLW 03H ;3响三声
MOVWF THREE
X3S_THREE:
CALL DELAY
CALL DELAY1S
CALL DELAY1S
DECFSZ THREE,1
GOTO X3S_THREE
MOVLW 20 ;20延时3秒
MOVWF LXXEndBuf
X3S_THREEEND:
CALL DELAY1S
DECFSZ LXXEndBuf,1
GOTO X3S_THREEEND
GOTO MAINLOOP
;*******************************************
LXX_CONTIUE:
MOVLW PortAStatus
TRIS RA
MOVLW PortBStatus
TRIS RB
MOVLW 07H ;预分频器分频比1/256
OPTION
CALL DELAY200us
CALL TESTZD
BTFSC FLAG,0
GOTO START_LXX
CALL DELAY200us
DECFSZ DEL10SBuf1,1
GOTO LXX_CONTIUE
DECFSZ DEL10SBuf2,1
GOTO LXX_CONTIUE
BCF FLAG,7 ;1分钟延时结束,FLAG7=0
GOTO MAINLOOP
START_LXX: ;开始连续响20秒
MOVLW 70 ;70
MOVWF LXXCount
START_LXX1:
CALL DELAY_LXX ;连续发声控制
DECFSZ LXXCount,1
GOTO START_LXX1
MOVLW 20 ;20延时3秒
MOVWF LXXEndBuf
START_LXXEND:
CALL DELAY1S
DECFSZ LXXEndBuf,1
GOTO START_LXXEND
GOTO LXX_CONTIUE
;*******************************************
NOP ;跑飞时软件捕捉,拉入正轨
NOP
GOTO MAINLOOP
NOP
NOP
GOTO MAINLOOP
;*******************************************
ORG 1FEH ;软件陷阱
GOTO MAINLOOP
;*******************************************
ORG PIC54
GOTO MAIN
END