P1   P2   P3

THE PROGRAM
(Download  2-InputAlarm.asm file and open it in Notepad). 
See  2-InputAlarm.hex file below:

The program is very complex and uses an interrupt feature that interrupts the Main routine every 2048 microseconds.
This feature is activated by setting the Global Interrupt bit in the INTCON file. The duration between each interrupt is determined by the value of the pre-scaler, multiplied by 256 (for  TMR0).
TMR0 is a timer that increments on every instruction-cycle and "ticks-over" from FF to 00 after 256 cycles.

LIST P=PIC16F628
;2-Input Alarm
include <P16F628.inc>
__CONFIG _CP_OFF & _LVP_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_CLKOUT & _MCLRE_off & _BODEN_off

Note: You cannot assemble this .asm file
        in MPASM as it is not formatted for
        assembly. Use the .asm file above.


;Ports:

PORTA equ 0x05
PORTB equ 0x06

;All others:

CMCON equ 0x1F
INTCON equ 0x0B
INTF equ 1
OPTION_REG equ 0x81
PCL equ 0x02
RP0 equ 5
RP1 equ 6
STATUS equ 0x03
T0IF equ 2
TMR0 equ 0x01
TRISA equ 0x85
TRISB equ 0x86
Z equ 2


;Configuration Bits:

_BODEN_ON                        equ H'3FFF'
_BODEN_OFF                      equ H'3FBF'
_CP_ALL                              equ H'03FF'
_CP_75                                equ H'17FF'
_CP_50                                equ H'2BFF'
_CP_OFF                             equ H'3FFF'
_PWRTE_OFF                      equ H'3FFF'
_PWRTE_ON                        equ H'3FF7'
_WDT_ON                            equ H'3FFF'
_WDT_OFF                          equ H'3FFB'
_LVP_ON                             equ H'3FFF'
_LVP_OFF                           equ H'3F7F'
_MCLRE_ON                        equ H'3FFF'
_MCLRE_OFF                      equ H'3FDF'
_ER_OSC_CLKOUT              equ H'3FFF'
_ER_OSC_NOCLKOUT         equ H'3FFE'
_INTRC_OSC_CLKOUT         equ  H'3FFD'
_INTRC_OSC_NOCLKOUT    equ H'3FFC'
_EXTCLK_OSC                     equ H'3FEF'
_LP_OSC                             equ H'3FEC'
_XT_OSC                             equ H'3FED'
_HS_OSC                            equ H'3FEE'



Alarm_state   equ 0x22
Stat_sav        equ 0x24
W_sav           equ 0x25
tmr_Flg1        equ 0x27
tmr_Flg2        equ 0x28
Puls_flgs       equ 0X29
mi_Flgs         equ 0x2A
cnt_Clicks     equ 0x2C
tbl_i              equ 0x2D



flg_RAoff      equ 0
flg_Zone2     equ 1
flg_Deboun   equ 2




flg_Dis         equ 0
flg_Ena        equ 1
flg_Yellow    equ 2
flg_Red        equ 3



bit_In             equ 0
bit_Z1            equ 1
bit_Z2            equ 2
bit_Amp_On   equ 3



bit_Red        equ 0
bit_Yel         equ 1
bit_Gre        equ 2
bit_Strobe    equ 3
bit_Buzz      equ 4
bit_Siren      equ 5
bit_Verb       equ 6
bit_Dog        equ 7



flg_Clk        equ 0
flg_Verb      equ 1
flg_Strobe   equ 2
flg_Buzz     equ 3
flg_Dog       equ 4
flg_Siren     equ 5
flg_Disarm  equ 6


flg_Waita       equ 0
flg_Waitb       equ 1
flg_Trig          equ 2
flg_Amp_On   equ 4










tmr_Clk           equ 0x30
tmr_Deboun     equ 0x31
tmr_Blink         equ 0x32
tmr_Trig           equ 0x33
tmr_Siren         equ 0x34
tmr_Buzz1       equ 0x35
tmr_Buzz2       equ 0x36
tmr_Disarm1    equ 0x37
tmr_Dog1         equ 0x3A
tmr_Strobe1     equ 0x3C
tmr_Strobe2     equ 0x3D
tmr_Verb1        equ 0x3F
tmr_Delay1       equ 0x42
tmr_Delay2       equ 0x43
tmr_Amp_On1  equ 0x46
tmr_Amp_On2  equ 0x47
tmr_Rearm1     equ 0x48
tmr_Rearm2     equ 0x49
tmr_Rearm3     equ 0x4A
ExitDel1           equ 0x4B
ExitDel2           equ 0x4C






lmt_Strobe2       equ 0x16
lmt_Amp_On2    equ 0x20
lmt_Disarm        equ 0xFF
lmt_Blink           equ 0x7E
lmt_Deboun       equ 0x20
lmt_Clk              equ 0xA0

;If you don't have "include <P16F628.inc>"
;file, the following will allow MPASM to ;assemble your program:
















































;Misc variables

;Contains alarm state


;Register of timer flags
;Register of more timer flags
;Pulse LED flags
;miscellaneous flags

;table index

;Miscellaneous flags

;Used to insure a double-click
;Used to turn off motion detector (ZONE) 2
;debouncing in progress


;Alarm State flags (bit number)

;Set State of alarm = "disable"
;Set State of alarm = "enable"
;Set State of alarm = "yellow alert"
;Set state of alarm = "red alert"

;PORTA bits

;switch input
;motion detector (ZONE) 1
;motion detector (ZONE) 2
;power amplifier

;PORTB bits

;red LED
;Yellow LED
;Green LED
;Strobe
;Buzzer
;Siren
;Verbal warning
;Barking dog


;Timer-1 flags








;Timer-2 flags





;Timer intervals
; tmr register variables are decremented & ;processed during ;interrupt
;processing if its corresponding flg is set in ;tmr_Flg1.
;must use two register
; variables to have intervals more a couple of seconds.

;time between control clicks
;Debounce interval
;interval that a blinking LED in on
;interval that an alarm trigger must be active
;Siren interval
;Buzzer interval
;Number of intervals Buzzer is "on"

;Barking Dogs warning interval


;Verbal warning interval
;shared by the isr routines that delay
;triggering and enabling alarm
;amplifier remain-on interval




;timing for duration of entry/exit beep
;timing for duration of entry/exit beep


;The following constants are the number of   ;2048 microseconds intervals or 2.1 second ;intervals allowed.

;2.1 second intervals for strobe light
;2.1 second intervals for amp to remain on 

; intervals for one blink of the running LEDs
;(7E = approximately one second)
;intervals to debounce (1/4 seconds)
;time when 2nd click becomes a double-click
 















tableS







































isr












isr_0





isr_1





isr_2






isr_3








isr_4














isr_5






isr_6













isr_7









isr_8












isr_8a






isr_9

 









isr_9a








isr_9b






isr_9z










isr_10







isr_11


isr_12








isr_13







Beep


Beep1







Main

























Loop










Check

Check1







Input














Input1



Input2


Input3

Input4





M_look













M_Look1

M_trig












Enable









Exit










Exit1

Exit2










Del1

Del1A






Del1B






Del2

Del2A






Del2B







Alrm_go









Alrm_r


Alrm_z





Entry














Entry1

Entry2
















SetYel




















SetRed



















SetDis
















Deboun
ORG 0
GOTO Main
NOP
NOP
ORG 4
GOTO isr








addwf PCL,1
retlw 0x0A0
retlw 0x025
retlw 0x0A0
retlw 0x035
retlw 0x0A0
retlw 0x070
retlw 0x020
retlw 0x050
retlw 0x0A0
retlw 0x030
retlw 0x0A0
retlw 0x050
retlw 0x090
retlw 0x050
retlw 0x0A0
retlw 0x070
retlw 0x0A0
retlw 0x050
retlw 0x020
retlw 0x050
retlw 0x020
retlw 0x050

















MOVWF W_sav
SWAPF STATUS,W
BCF STATUS,RP0
MOVWF Stat_sav
BTFSS Alarm_state, flg_Dis
GOTO isr_0
DECFSZ tmr_Rearm3,1
GOTO isr_0
DECFSZ tmr_Rearm2,1
GOTO isr_0
DECFSZ tmr_Rearm1,1
GOTO isr_0
CALL Enable
BTFSS mi_Flgs, flg_Deboun
GOTO isr_1
DECFSZ tmr_Deboun,1
GOTO isr_2
BCF mi_Flgs, flg_Deboun

BTFSS tmr_Flg1, flg_Clk
GOTO isr_2
DECFSZ tmr_Clk,1
GOTO isr_2
BCF tmr_Flg1, flg_Clk

BTFSS tmr_Flg1, flg_Verb
GOTO isr_3
DECFSZ tmr_Verb1,1
GOTO isr_3
BCF tmr_Flg1, flg_Verb
BCF PORTB, bit_Verb

BTFSS tmr_Flg1, flg_Strobe
GOTO isr_4
DECFSZ tmr_Strobe1,1
GOTO isr_4
DECFSZ tmr_Strobe2,1
GOTO isr_4
BCF tmr_Flg1, flg_Strobe
BCF PORTB, bit_Strobe

BTFSS tmr_Flg1, flg_Buzz
GOTO isr_5
DECFSZ tmr_Buzz1,1
GOTO isr_5
MOVLW 0x10
XORWF PORTB,1
MOVLW 0x0FF
BTFSS PORTB, bit_Buzz
MOVLW 0x080
MOVWF tmr_Buzz1
DECFSZ tmr_Buzz2,1
GOTO isr_5
BCF tmr_Flg1, flg_Buzz
BCF PORTB, bit_Buzz

BTFSS tmr_Flg1, flg_Dog
GOTO isr_6
DECFSZ tmr_Dog1,1
GOTO isr_6
BCF tmr_Flg1, flg_Dog
BCF PORTB, bit_Dog

BTFSS tmr_Flg1, flg_Siren
GOTO isr_7
DECFSZ tmr_Siren, 1
GOTO isr_7
MOVLW 0x20
XORWF PORTB,1
MOVF tbl_i,0
CALL tableS
MOVWF tmr_Siren
DECFSZ tbl_i,1
GOTO isr_7
BCF tmr_Flg1, flg_Siren
BCF PORTB, bit_Siren

BTFSS tmr_Flg1, flg_Disarm
GOTO isr_8
DECFSZ tmr_Disarm1,1
GOTO isr_8
BCF tmr_Flg1, flg_Disarm
CALL SetDis
MOVLW 0xFF
MOVWF tmr_Deboun
BSF mi_Flgs, flg_Deboun

BTFSS tmr_Flg2, flg_Waita
GOTO isr_9
DECFSZ tmr_Delay1,1
GOTO isr_9
DECFSZ tmr_Delay2,1
GOTO isr_9
BCF tmr_Flg2, flg_Waita
CALL Beep
BTFSS Alarm_state, flg_Yellow
GOTO isr_8a
CALL SetYel
GOTO isr_9

BTFSC Alarm_state, flg_Red
CALL SetRed





BTFSS Alarm_state, flg_Ena
GOTO isr_10
DECFSZ tmr_Blink,1
GOTO isr_10
BTFSS tmr_Flg2, flg_Waitb
GOTO isr_9a
MOVLW b'00000100'
BTFSC PORTB, bit_Gre
MOVLW b'00000000'
IORWF PORTB, 1
GOTO isr_9z

BTFSS mi_Flgs,flg_Zone2
GOTO isr_9b
MOVLW b'00000100'
BTFSC PORTB, bit_Gre
MOVLW b'00000010'
BTFSC PORTB, bit_Yel
MOVLW b'00000001'
GOTO isr_9z

MOVLW b'00000100'
BTFSC PORTB, bit_Gre
MOVLW b'00000001'
BTFSC PORTB, bit_Red



MOVLW b'00000010'
BCF PORTB, bit_Gre
BCF PORTB, bit_Yel
BCF PORTB, bit_Red
IORWF PORTB, 1
MOVLW lmt_Blink
MOVWF tmr_Blink




BTFSS tmr_Flg2, flg_Waitb
GOTO isr_11
DECFSZ tmr_Delay1, 1
GOTO isr_11
DECFSZ tmr_Delay2, 1
GOTO isr_11
BCF tmr_Flg2, flg_Waitb

NOP


BTFSS tmr_Flg2, flg_Amp_On
GOTO isr_13
DECFSZ tmr_Amp_On1,1
GOTO isr_13
DECFSZ tmr_Amp_On2,1
GOTO isr_13
BCF tmr_Flg2, flg_Amp_On
BSF PORTA, bit_Amp_On

BCF INTCON,T0IF
BCF INTCON,INTF
SWAPF Stat_sav,W
MOVWF STATUS
SWAPF W_sav,F
SWAPF W_sav,W
RETFIE

BSF PORTB,4
MOVLW 0x80
MOVWF ExitDel2
DECFSZ ExitDel1
GOTO Beep1
DECFSZ ExitDel2
GOTO Beep1
BCF PORTB,4
RETURN


CLRF PORTA
MOVLW 0x07
MOVWF CMCON
CLRF PORTB
BCF STATUS, RP1
BSF STATUS, RP0
MOVLW b'00000111'
MOVWF TRISA ^ 0x080
CLRF TRISB ^ 0x080
CLRWDT
MOVLW b'00000100'




MOVWF Option_Reg ^ 0x080
BCF STATUS, RP0
CLRF TMR0
CALL SetDis
MOVLW 0xA0
MOVWF INTCON
CLRF mi_Flgs
BSF mi_Flgs,flg_RAoff



BTFSC mi_Flgs, flg_Deboun
GOTO M_look
BTFSS tmr_Flg1, flg_Disarm
GOTO Check
BTFSS PORTA,0
GOTO Check1
Call Deboun
GOTO M_look



BTFSC PORTA,0
GOTO Input
BTFSC mi_Flgs,flg_RAoff
GOTO M_look
CALL Deboun
BSF mi_Flgs,flg_RAoff
BCF tmr_Flg1, flg_Disarm
GOTO M_look


BTFSS mi_Flgs,flg_RAoff
GOTO Input3
CALL Deboun
BCF mi_Flgs,flg_RAoff
BTFSS Alarm_state,flg_Ena
GOTO Input1
INCF cnt_Clicks,1
MOVLW 0x03
SUBWF cnt_Clicks,0
BTFSS STATUS,Z
GOTO Input4
MOVLW b'00000010'
XORWF mi_Flgs,flg_Zone2
CLRF cnt_Clicks
GOTO Input4
BTFSS tmr_Flg1, flg_Clk
GOTO Input2
CALL Enable
GOTO M_look
MOVLW lmt_Clk
MOVWF tmr_Clk
BSF tmr_Flg1, flg_Clk
BTFSC Alarm_state, flg_Dis
GOTO Loop
MOVLW lmt_Disarm
MOVWF tmr_Disarm1
BSF tmr_Flg1, flg_Disarm


 
BTFSC Alarm_state, flg_Dis
GOTO Loop
BTFSC tmr_Flg2, flg_Waita
GOTO Loop
BTFSC tmr_Flg2, flg_Waitb
GOTO Loop
BTFSC tmr_Flg2, flg_Trig
GOTO Loop
BTFSC tmr_Flg1, flg_Strobe
GOTO Loop
BTFSC mi_Flgs,flg_Zone2
GOTO M_Look1
BTFSC PORTA,bit_Z2
GOTO M_trig
BTFSC PORTA,bit_Z1
GOTO Loop
CALL Alrm_go
GOTO Loop











CLRF 4Eh
CLRF cnt_Clicks
CLRF tmr_Flg1
CLRF tmr_Flg2
CLRF PORTB
BSF PORTA, bit_Amp_On
MOVLW 0x00
MOVWF INTCON
MOVLW 30h
MOVWF 4Dh
BSF 06,2
BSF 06,4
CALL Del2
BCF 06,4
CALL Del1
BCF 06,2
CALL Del1
BTFSS 4Eh,0
GOTO Exit1
BCF 4Eh,0
GOTO Exit2
DECFSZ 4Dh,1
GOTO Exit
MOVLW 0x0A0
MOVWF INTCON
CLRF tmr_Delay1
MOVLW 0x03
MOVWF tmr_Delay2
CLRF Alarm_state ;
BSF Alarm_state, flg_Ena
BCF tmr_Flg2,flg_Waita
BSF tmr_Flg2,flg_Waitb
RETURN

MOVLW 0A0h
MOVWF 4Bh
NOP
MOVLW 2Ch
SUBWF 4Dh,0
BTFSC 03,0
GOTO Del1B
BTFSC 05,0
BSF 4E,0
DECFSZ 4C,1
GOTO Del1A
DECFSZ 4B,1
GOTO Del1A
RETURN


MOVLW 20h
MOVWF 4Bh
NOP
MOVLW 2Ch
SUBWF 4Dh,0
BTFSC 03,0
GOTO Del2B
BTFSC 05,0
BSF 4E,0
DECFSZ 4C,1
GOTO Del2A
DECFSZ 4B,1
GOTO Del2A
RETURN



CALL Beep
BCF PORTB, bit_Gre
BCF PORTB, bit_Red
BCF PORTB, bit_Yel
BTFSS Alarm_state, flg_Ena
GOTO Alrm_r
CLRF Alarm_state
BSF Alarm_state, flg_Yellow
BSF PORTB, bit_Yel
GOTO Alrm_z
CLRF Alarm_state
BSF Alarm_state, flg_Red
BSF PORTB, bit_Red
CLRF 4Eh
MOVLW 0x00
MOVWF INTCON
MOVLW 30h
MOVWF 4Dh
BCF 06,1
BSF 06,0
BSF 06,4
CALL Del2
BCF 06,4
CALL Del2
BSF 06,4
CALL Del2
BCF 06,4
CALL Del1
BCF 06,0
CALL Del1
BTFSS 4Eh,0
GOTO Entry1
BCF 4Eh,0
GOTO Entry2
DECFSZ 4Dh,1
GOTO Entry
MOVLW 0x0A0
MOVWF INTCON
MOVLW 0x0FF
MOVWF tmr_Delay1
MOVLW 0x02
MOVWF tmr_Delay2
BCF tmr_Flg2, flg_Waitb
BSF tmr_Flg2, flg_Waita
BCF PORTA, bit_Amp_On
CLRF tmr_Amp_On1
MOVLW lmt_Amp_On2
MOVWF tmr_Amp_On2
BSF tmr_Flg2, flg_Amp_On
RETURN



CLRF tmr_Strobe1
MOVLW lmt_Strobe2
MOVWF tmr_Strobe2
BSF tmr_Flg1, flg_Strobe
BSF PORTB, bit_Strobe
MOVLW 0x01
MOVWF tmr_Siren
MOVLW 0x015
MOVWF tbl_i
BSF tmr_Flg1, flg_Siren
MOVLW 0x040
MOVWF tmr_Verb1
BSF tmr_Flg1, flg_Verb
BSF PORTB, bit_Verb
MOVLW 0x040
MOVWF tmr_Dog1
BSF tmr_Flg1, flg_Dog
BSF PORTB, bit_Dog
RETURN


CLRF tmr_Strobe1
MOVLW lmt_Strobe2
MOVWF tmr_Strobe2
BSF tmr_Flg1, flg_Strobe
BSF PORTB, bit_Strobe
MOVLW 6
MOVWF tmr_Buzz1
MOVLW 19
MOVWF tmr_Buzz2
BSF tmr_Flg1, flg_Buzz
BCF PORTB, bit_Buzz
MOVLW 0x040
MOVWF tmr_Dog1
BSF tmr_Flg1, flg_Dog
BSF PORTB, bit_Dog
RETURN




MOVLW 1
MOVWF Alarm_state
CLRF tmr_Flg1
CLRF tmr_Flg2
CLRF cnt_Clicks
MOVLW b'00000100'
MOVWF PORTB
BSF PORTA, bit_Amp_On
MOVLW 0x0FF
MOVWF tmr_Rearm1
MOVWF tmr_Rearm2
MOVLW 0x01A
MOVWF tmr_Rearm3
RETURN



MOVLW lmt_Deboun
MOVWF tmr_Deboun
BSF mi_Flgs, flg_Deboun
RETURN

END





;interrupts always vector (come) to here

Table for siren intervals
(makes siren wail at ;uneven intervals. If you move the call to this
;table from the isr routine to another memory ;location or move this table, check Microchip
;pub ANS556 to avoid some possible problems.



;1
;2
;3
;4
;5
;6
;7
;8
;9
;A
;B
;C
;D
;E
;F
;10
;11
;12
;13
;14
;15
;16

;Interrupt Service Routine (ISR). Servicing TMR0 interrupts only. This ISR allows Main to turn on an output port, set up a counter that specifies how many timer interrupts (2048 microseconds intervals) a function is to remain on. 126 (0x07E) intervals is about 1 second. It is also used for other functions that need something done after a certain time interval such as setting a 'debounce-off' flag, implement a delay before enabling the alarm (to allow someone to leave),
implement a delay before going to a Yellow or Red Alert mode, maintaining a time-out interval for "double clicks" on RA0 input and others




;first save critical registers
;always change to bank 0

;is alarm disabled?
;no



;This code eventually enables the alarm
in a few hours. I put this in because I would get distracted and forget to enable the alarm after I left the garage.

;Debouncing?
;no
;time up?    
;no
;Turn off "debounce in progress" flag

;looking for a double click?

;count down

;yes - time is up

;verbal warning timer on?
;no



;turn off verbal warning

;strobe light timer on?
;no


;count-down reached?


;turn off strobe

;Buzzer/Horn handling ?
;no


;buzzer/horn bit
;reverse PORTB Buzzer State
;set buzzer-on interval
;is buzzer on?
;yes, set buzzer-off interval

;count-down times buzzer is turned on and off
;limit not reached

;turn off buzzer

;Barking dogs handling? (amplifier should be on)




;turn off barking dogs

;Siren handling?
;no


;Siren bit
;Reverse PORTB Siren State

;Call Siren table
;set siren interval timer



;turn off siren

;Disarm?

;has switch been closed long enough?

;yes - we have a Disarm command

;give user 2.1 seconds to release switch after
;Disarm is triggered before more RA0 inputs are ;processed

;Waiting to set off alarm
;no
;wait several seconds in case someone
;entered to turn off alarm.
;count-down reached?
;no




;yellow alert



; red alert



;If the alarm is in "enabled" mode, then blink
;lights from from top to bottom (or bottom to top
;if Zone 2 is disabled)
;is alarm in enabled mode?
;no
;time to blink a different color?
;no
;Are we waiting to enable alarm?
;no
;set green as default color
;was PortB green led already on?
;no then set W = no LEDs
;update PORTB with new LED display


;Zone 2 disabled?
;no reverse order lights blink
;set green as default color
;was PortB green led already on?
;then set W = yellow LED
;was PortB yellow LED already on?
;then set W = Red

;Blink lights in reverse order of isr_9
;was PortB green LED already on?
;then set W = Red
;was PortB yellow led already on?



;then set W = yellow led



;update PORTB with new LED display

;Reset count-down timer

;Allow time for someone to leave before clearing ;flg_Waitb.  All motion detector input is ignored
;until flg_Waitb is clear.
;Flag set?
;no
;wait for another interrupt?
;yes
;yet some more?
;yes
;clear flag

;not used

;power off the amplifier after the specified time.
;is amplifier on?
;no





;turn off amplifier




;restore status (and Bank used at time of
;interrupt)
;restore w without changing status











;Main program - Setup

;clear Port A
;turn comparators off and enable
;pins for I/O functions
;clear Port B

;select bank 1
;RA0, RA1, RA2 = input

;Port B - all output
;clear WDT and prescaler
;prescaler (1:32)


;use MOVLW b'00000001' prescaler - for debugging

;TMR0 interrupts = 6 microseconds apart
;bank 0
;clear Timer0 register
;startup in disabled mode
;set GIE <7> and T0IE <5>
;enable Interrupts
;miscellaneous flags

;Set button released flag

Main program - Loop

;debounce in progress?
;yes - skip RA0 input processing
;disarm in progress?
;no - do normal RA0 input processing
;still in progress?
;no - do normal RA0 input processing
;Yes - debounce here to implement a 'sampling' ;effect. Skip RA0 input processing

; Main Loop - Check for command input (commands entered via the momentary switch)
;check RA0 (command input)
;RA0 is high so go process it
;RA0 is low - just released?
;No - it has been low
;Debounce
;Set "RA0 is low" flag
;turn any off disarm-in-progress


;Main Loop - Process command input.
;just turned on?
;no - this can happen only on 2nd click of a
;double-click.  Yes - so debounce it
;Set "RA0 is high" flag
;is alarm enabled?
;No

;number Clicks = 3

;while in enabled mode?



;reverse Zone2 enabled/disabled status


;were we waiting for a double click?
;no


;get double-click interval

;start the double click timer
;is alarm already disabled?
;yes
;start 'disarm-in-progress'

;start the disable command timer

;Main Loop - looks for input from the motion detectors.
;is alarm disabled?
;yes - don't look for an intruder
;give someone time to enter & turn off alarm

;give someone time to enable & leave room?
;yes
;already processing a motion trigger?
;yes
;is strobe light on ?
;yes, let existing alarm complete
;is zone-2 disabled?
;yes - check zone-1
;zone-2 low? (normally low)
;No
;zone-1 high? (normally high)
;Yes



;Subroutines - Logic in the Main Loop was
;simplified by moving code that performed a
;well-defined function to a subroutine.
Sometimes that is the sole purpose of a
;subroutine, and, in fact does not shorten the
;program or improve anything but readability.


Subroutine - Enable/Reset the alarm


;clear button-detect flag in delay routine



;clear Port B - stop all alarms
;turn off amplifier

;turn off interrupts
;number of beeps/flashes
;storage file for decrementing
;turn on green LED
;turn on beeper
;short delay
;turn off beeper
;call long delay




;reset the "button-pressed" flag




;turn on interrupts
; set delay
; wait another 2 seconds to enable


; Set alarm to enabled mode




;this is the long delay
;file to decrement

;allow 3 beeps before button detected

;test carry flag. Will be SET if more than file 2Dh


;button has been detected- flag it







;this is the short delay
;file to decrement

;allow 3 beeps before button detected

;test carry flag. Will be set if more


;button has been detected- flag it






Subroutine - Turn on Alarm
Set delay time and flags for isr routine.




;previously triggered?
;yes


;set LEDs to yellow alert



;set LEDs to Red alert
;clear "button-pressed" flag file

;turn off interrupts
;48 beeps/flashes for entry

;clear orange LED
;turn on red LED
;turn on beeper
;short delay
;turn off beeper
;short delay
;turn on beeper
;short delay
;turn off beeper
;call long delay


;test button-detect flag

;clear button-detect flag in delay routine




;turn on interrupts
;Set delay time for two extra seconds



;clear exit delay flag
;set entry delay flag
;turn on amp (Yes - LOW to turn amp on)
;set 'Power-on' flag & timer





Subroutine - Go to Yellow Alert

;length of time strobe is to remain on


;flag interrupt service routine (ISR) to handle
;turn on strobe light.

;time interval to turn Siren on

;set table index - defines 'wailing' intervals
;TMR0 interrupts to handle siren
;'verbal warning' needs only a pulse to trigger it

;tmr0 interrupts will handle verbal warning
;start verbal warning (amp should be powered
;up)  'barking dog' needs only a pulse to trigger
;it
;set timer
;start barking


Subroutine - Go to Red Alert
;length of time strobe is to remain on


;flag 'strobe' ISR handling
;turn on strobe light.
;start with short pulse (Load Buzzer)

;number of pulses to generate
;count-down timer
;so tmr0 interrupts will handle buzzer
;start with buzzer off
;barking dog module needs only need a pulse to
;start it
;set timer
;start barking (amp should be powered up by ;now)


Subroutine - Set Alarm Disabled


;set Alarm state to disabled
;turn off anything that is on
;turn off anything that is on

;set green LED  -  ON

;turn off amplifier


;Set automatic re-arm alarm timer to 4 hours
;9 minutes intervals per count here



Subroutine - Turn on Debounce


;set Debounce interval
;start the Debounce timer
 
2-Input Alarm.hex  (click for file)

:02000000B7281F
:080008001C288207A0342534F6
:10001000A0343534A034703420345034A03430341B
:10002000A034503490345034A0347034A034503460
:100030002034503420345034A500030E8312A40021
:10004000221C2928CA0B2928C90B2928C80B2928B2
:1000500007212A1D2E28B10B33282A11271C3328EB
:10006000B00B33282710A71C3928BF0B3928A7103D
:100070000613271D4128BC0B4128BD0B4128271121
:100080008611A71D4F28B50B4F2810308606FF306C
:10009000061E8030B500B60B4F28A7110612271E8A
:1000A0005528BA0B552827128613A71E6228B40BB1
:1000B0006228203086062D080520B400AD0B62288A
:1000C000A7128612271F6B28B70B6B2827139921BD
:1000D000FF30B1002A15281C7928C20B7928C30BE0
:1000E00079282810AE20221D772876217928A21998
:1000F0008921A21C9728B20B9728A81C84280430B9
:100100000619003086049128AA1C8C280430061990
:100110000230861801309128043006190130061883
:10012000023006118610061086047E30B200A81C2C
:100130009E28C20B9E28C30B9E28A8100000281ED4
:10014000A728C60BA728C70BA728281285150B11AF
:100150008B10240E8300A50E250E09000616803094
:10016000CC00CB0BB128CC0BB128061208008501BE
:1001700007309F0086010313831607308500860130
:10018000640004308100831281019921A0308B002A
:10019000AA012A142A19F528271FD228051CD428B9
:1001A000A721F5280518DA282A18F528A7212A14E6
:1001B0002713F5282A1CF028A7212A10A21CE928B9
:1001C000AC0A03302C02031DF2280230AA06AC014F
:1001D000F228271CED280721F528A030B0002714AD
:1001E0002218CA28FF30B70027172218CA28281853
:1001F000CA28A818CA282819CA282719CA28AA1834
:10020000032905190529851CCA284421CA28CE01BD
:10021000AC01A701A8018601851500308B003030A4
:10022000CD000615061636210612282106112821B2
:100230004E1C1C294E101E29CD0B1129A0308B00FD
:10024000C2010330C300A201A2142810A8140800A0
:10025000A030CB0000002C304D02031831290518C6
:100260004E14CC0B2A29CB0B2A2908002030CB00B6
:1002700000002C304D0203183F2905184E14CC0BFA
:100280003829CB0B38290800AE200611061086103D
:10029000A21C4E29A201221586145129A201A215E1
:1002A0000614CE0100308B003030CD0086100614CD
:1002B0000616362106123621061636210612282188
:1002C000061028214E1C66294E106829CD0B57298F
:1002D000A0308B00FF30C2000230C300A8102814E9
:1002E0008511C6012030C70028160800BC01163051
:1002F000BD00271586150130B4001530AD00A716D6
:100300004030BF00A71406174030BA0027168617E2
:100310000800BC011630BD00271586150630B50053
:100320001930B600A71506124030BA0027168617F6
:1003300008000130A200A701A801AC01023086002C
:100340008515FF30C800C9001A30CA0008002030E7
:06035000B1002A150800AF
:02400E00193F58
:00000001FF

 

 

P1   P2   P3