注:警报音频率为1.8K到3.5K之间,具体请查资料
OSCILLATION:R/C =晶振 CLOCK = 2
Frequency =4MHZ
;=================================================================*/
Fre_COUNT EQU 0X37 ;'声音频率变化计数器,从1.8~3.55KHZ
Fre_Repeat EQU 0x38 ;'同一频率的重复次数
SOUND_TEMP EQU 0X39
;'Replace program variable value and debug is more than easy.
S_Loop EQU 67 ;'MAX-MIN
S_MAX EQU 138
S_MIN EQU 71
S_Repeat EQU 4
;开始0.2秒发音
SOUND200ms:
SOUND_LH: ;1.8~3.55
MOV A,@S_Loop ;66=134-68
MOV Fre_COUNT,A
SOUND_LH_LP:
MOV A,@S_Repeat ;
MOV Fre_Repeat,A
MOV A,Fre_COUNT
ADD A,@S_MIN ;
repeat0_lp BS PORT6,BUZ
CALL SOUNDDELAY0
BC PORT6,BUZ
CALL SOUNDDELAY0
DJZ Fre_Repeat
JMP repeat0_lp
DJZ Fre_COUNT
JMP SOUND_LH_LP
SOUND_HL: ;3.55~1.8
MOV A,@S_Loop ;66=134-68
MOV Fre_COUNT,A
SOUND_HL_LP:
MOV A,@S_Repeat ;
MOV Fre_Repeat,A
MOV A,Fre_COUNT
SUB A,@S_MAX ;
repeat1_lp BS PORT6,BUZ
CALL SOUNDDELAY0
BC PORT6,BUZ
CALL SOUNDDELAY0
DJZ Fre_Repeat
JMP repeat1_lp
DJZ Fre_COUNT
JMP SOUND_HL_LP
SOUND_END: ;
RET
;**********************************************************
Sound2s: ;2S内短鸣两声
WARNING1:
CALL Sound200ms
CALL Delay800ms
CALL Sound200ms
CALL Delay800ms
RET
Delay800ms:
CLR TIME1 ;'get ready for 0.8 second delay.
Sound_delay MOV A,@196 ;'delay 0.8 second
SUB A,TIME1
JBS R3,0
JMP Sound_delay
RET
;************************************************
Sound15s: ;连续报警15S
WARNING2:
MOV A,@73
MOV SOUND_TEMP,A
Sound1s_lp CALL Sound200ms
JBC PORT6,SDT ;'SDT上电立即中断报警
RET
DJZ SOUND_TEMP
JMP Sound1s_lp
RET
;============================
SOUNDDELAY1 EQU 0X3A
sounddelay:
mov a,@18 ;
sounddelay0 mov sounddelay1,a ;=(A*9)+3
wdtc
sounddelayus_1:
nop
nop
nop
nop
nop
nop
djz sounddelay1
jmp sounddelayus_1
ret
复制代码
;数据寄存器定义
NUMBER0 EQU 0X1D ;振动宽度计数器
GRADEDATA EQU EQU0X1E;当前灵敏度
COM_DATA_REC EQU 0X1F;上一次数据寄存器
;PSW位定义
TCINTBIT EQU 0;中断计数标志位,约为750ms(TCC Rate=1:256)
VibraBIT EQU 1;是否达到当前灵敏度宽度,即是否有振动
CHECK_Vibra:
CELLECTION_VIB:
CLR NUMBER ;检测振动前先把计数器清0
CLR TCC
CLR NUMBER0
BC PSW,TCINTBIT
CELLECTION_L: ;采集数据子程序
MOV A,@89 ;730ms
SUB A,NUMBER
JBC R3,0
BS PSW,TCINTBIT
JBC PSW,TCINTBIT
JMP CELLECTION_CN4 ;是否超时
JBS PORT5,SEN
JMP CELLECTION_L
CELLECTION:
JBS PORT5,SEN
JMP CELLECTION_END
MOV A,@53 ;DELAY 60us
CALL DELAY0
INC NUMBER0
JMP CELLECTION
CELLECTION_END:
MOV A,GRADEDATA ;比较振动灵敏度
SUB A,NUMBER0
JBS R3,0
JMP CLRNUMBER0
CLR NUMBER0
BS PSW,VibraBIT ;置检测到振动标志
ret
CELLECTION_CN4:
CLR NUMBER0
BC PSW,TCINTBIT
BC PSW,VibraBIT
RET
CLRNUMBER0:
CLR NUMBER0
JMP CELLECTION_L
复制代码