Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol MP3_SET_VOLUME = $06 ; Set the volume
Symbol MAX_VOLUME = $1E ; Max volume level, $1E = 30
Symbol Busy_Delay = 200 ; Change Busy delay value here
Symbol PoliceFlash = B.1 ;power mosfet
Symbol FloodLED = B.2 ;power mosfet
Symbol Busy_Pin = PinB.3 ; DF Player Busy Pin
Symbol TX = B.4 ;DFPlayer RX
Symbol WarningLED = B.5 ;hardware flashing RED LED
Symbol In3 = PinC.0 ;Final warning - sound 0005
Symbol In2 = PinC.1 ;Armed - sound 0006, Dis-Armed - sound 0004
Symbol In1 = pinC.2 ;First entry - sound 0003
Symbol PIR = pinC.3 ;Main entry - sound 0001 day, 0002 night
Symbol LDR = C.4
Symbol LDR_DAY = 105 ; Greater or equal this it's day
Symbol LDR_NIGHT = 95 ; Lower or equal this it's night
Symbol reserveW0 = w0 ; b1:b0
Symbol dayOrNight = w1 ; Set to IS_DAY or IS_NIGHT
Symbol IS_DAY = 0 ; Set 'dayOrNight' to 0 to use 'On dayOrNight Goto Day, Night'
Symbol IS_NIGHT = 1 ; Set 'dayOrNight' to 1 to use 'On dayOrNight Goto Day,Night'
Symbol breached = b10
Symbol Armed_state = b11
;---------------------------------------------------------
Begin:
SerTxd("Armed Status is Armed - sound 0006", CR, LF)
;Armed_state = 0
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $06, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
;---------------------------------------------------------
gosub Enable_interrupt
Main:
;do
;wait 45 ; Allow PIR to settle down before code starts
;wait 45 ; two waits because of 65 is the limit
;---------------------------------------------------------
What_time:
Gosub DetermineDayOrNight
On dayOrNight Goto Day, Night
;---------------------------------------------------------
Day:
#IfDef SIMULATING
If dayOrNight = IS_DAY Then
SerTxd("Day ")
Else
SerTxd("Night ")
EndIf
#EndIf
low FloodLED ; turn off light at day
SerTxd(" Floodlight off", CR, LF)
if PIR = 1 then gosub Day_warning ;Initial warning
if In1 = 1 then gosub first_entry ; second warning
if In2 = 1 then gosub Armed_status ;Dis-armed or Armed
if In3 = 1 then gosub Final_warning ; Final warning
goto main
;---------------------------------------------------------
Night:
#IfDef SIMULATING
If dayOrNight = IS_DAY Then
SerTxd("Day ")
Else
SerTxd("Night ")
EndIf
#EndIf
high FloodLED ; turn on light at night
SerTxd(" Floodlight on ", CR, LF)
if PIR = 1 then gosub Night_warning ;Initial warning
if In1 = 1 then gosub first_entry ; Second warning
if In2 = 1 then gosub Armed_status ;Dis-armed or Armed
if In3 = 1 then gosub Final_warning ; Final warning
goto main
;---------------------------------------------------------
DetermineDayOrNight:
ReadAdc LDR, b10 ; Read LDR and set 'dayOrNight'
If b10 > LDR_DAY Then
dayOrNight = IS_DAY
End If
If b10 < LDR_NIGHT Then
dayOrNight = IS_NIGHT
End If
;---------------------------------------------------------
Return
Day_warning:
SerTxd("Day_warning sound 0001", CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $01, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
; further code to be added here
Return
;---------------------------------------------------------
Night_warning:
SerTxd("Night_warning sound 0002", CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $02, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
; further code to be added here
Return
;---------------------------------------------------------
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
Return
;---------------------------------------------------------
first_entry: ;PinC.2
SerTxd("First Entry breach sound 0003", CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $03, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
; further code to be added here
return
;---------------------------------------------------------
Armed_status: ; PinC.1
if Armed_state = 0 then
gosub armed
else
gosub disarmed
endif
return
;---------------------------------------------------------
Warning_Led: ;B.5
if breached = 1 then high WarningLED
SerTxd("System has been breached ", CR, LF)
; turn off system with key to reset warning light
endif
Return
;---------------------------------------------------------
Final_warning: ;B.1 once started will flash for 3 minutes
SerTxd("PoliceFlash sound 0005", CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $05, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
high PoliceFlash
SerTxd("PoliceFlash on ", CR, LF)
for b9 = 1 to 18 ; 180 = 3 minutes
pause 60;000 ; wait 60 seconds REDUCED FOR TESTING PURPOSES
next
breached = 1
low PoliceFlash ; stop flashing lights
SerTxd("PoliceFlash off ", CR, LF)
gosub Warning_Led
Return
armed:
SerTxd("System is Armed sound 0004 ",#Armed_state, CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $04, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
toggle Armed_state
SerTxd("Armed state now is ",#Armed_state, CR, LF)
return
Disarmed:
SerTxd("System is Disarmed sound 0007 ",#Armed_state, CR, LF)
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, $0F, $00, $01, $07, $EF )
SerTxd(" ", CR, LF)
gosub Check_Busy
SetFreq MDEFAULT
toggle Armed_state
SerTxd("Armed state now is ",#Armed_state, CR, LF)
return
;---------------------------------------------------------
interrupt:
gosub Armed_status
Enable_interrupt:
do
loop while PinC.1 = 1 ;wait for Pin to go low, else interrupt
;triggers immediately on return statement!
setint %00000010,%00000010 ;enable interrupt on C.1 going high
return