PIC16C54 ile motorsiklet alarmı

Başlatan ilker_32, 23 Temmuz 2009, 12:20:57

ilker_32



       title   "microalarm"
       ;
       ;       Version  1.1
       ;
       ;       A. Nixon                240695
       ;
       ;       71kHz clock
       ;       56uS instruction time
       ;       prescaler set 1 : 32 division
       ;       rtcc set to 190, = 0 in approx 100mS, = loop cycle time
       ;
       ;
       ;                 ** alarm operation **
       ;
       ;       *  Alarm is armed when the ignition is turned on
       ;          for more than 2 secs and less than 5 secs, then is
       ;          turned off and left off for more than 3 seconds.
       ;       *  Alarm is cancelled when ignition is turned back on
       ;       *  If ignition is kept on for longer than 5 seconds, then
       ;          the alarm will not arm.
       ;       *  Turning the ignition on will kill the siren and disable
       ;          the alarm.
       ;      
       ;       *  siren announce alarm status
       ;       *  1 beep indicates alarm is now armed
       ;       *  2 beeps indicates alarm was tampered with
       ;       *  3 beeps indicates that alarm was set, but is in a
       ;          triggered condition and has disarmed itself
       ;
       ;
list p=16c54    ; processor type
       ;
       ;
       ;       equates list
       ;
       z equ 2h
       carry equ 0h
       rtcc equ 1h
       status equ 3h
       fsr equ 4h
       porta equ 5h
       portb equ 6h
       ;
       ;
       ;       output port assignments
       ;
       ;
       siren equ 7h    ; portb bit 7 - siren
       ;
       ign equ 1h      ; porta bit 1 - ignition
       sensor equ 1h   ; portb bit 1 - sensor
       ;
       ;
       ;
       ;       register list
       ;
       almset equ 0ah  ; flag, is alarm set
       beepfl equ 0ch  ; flag, is siren to beep
       beepct equ 0dh  ; times siren is to beep
       igdebn equ 0eh  ; ignition debounce counter
       igstat equ 0fh  ; ignition switch status flag
       error equ 10h   ; error status
       armed equ 11h   ; armed status
       onstat equ 12h  ; ignition on status
       icount equ 13h  ; ignition on/off counter
       triger equ 14h  ; trigger status
       sndebn equ 15h  ; sensor debounce counter
       sirenL equ 16h  ; siren on counter L
       sirenH equ 17h  ; siren on counter H
       igchan equ 18h  ; ignition change status
       tamper equ 19h  ; tamper announce timer
       beeptm equ 1ah  ; beep off timer
       ;
       ;       program start
       ;
       org 0h
       ;
start   movlw b'11111111'
;/start   clrw
       tris porta      ; all inputs
       movlw b'01111111'     ;/
       tris portb      ; portb bit 7 0/p, all others i/p's
       clrf porta
       clrf portb
       clrf almset
       clrf beepfl
       clrf beepct
       movlw .6        ; set for 6 debounce loops for ignition
       movwf igdebn
       clrf igstat
       clrf error
       clrf armed
       clrf onstat
       clrf icount
       clrf triger
       clrf sndebn
       clrf sirenL
       clrf sirenH
       clrf igchan
       clrf tamper
       clrf beeptm
       ;
       movlw b'11000100'    ;/
       option          ;/ set rtcc timing
       ;
       movlw .225      ;/
       movwf rtcc      ;/
       ;
mnloop  movf rtcc,w
       btfss status,z
       goto mnloop     ; wait here for rtcc to = 0, 50ms loop
       ;
       movlw .225      ;/
       movwf rtcc      ;/ reset rtcc timing
       ;
       ; Beep siren routine. The siren is turned on for 50mS and
       ; off every for 100mS.
       ; BEEPCT is decremented every time the siren is turned on.
       ;
       movf beepfl     ; if <> 0 then beep siren
       btfsc status,z
       goto dbchek     ; no beep siren
       ;
       btfsc portb,siren ; (7) test siren status
       goto siron
       ;
       movf beepct     ; if = 0 then exit, else beep siren and decrement
       btfss status,z
       goto dosirn
       ;
       clrf beepfl     ; clear the beep flag and exit
       goto dbchek
       ;
dosirn  movf beeptm
       btfss status,z
       goto onsirn
       ;
       incf beeptm
       goto dbchek
       ;
onsirn  decf beepct     ; beep counter - 1
       bsf portb,siren ; (7) turn siren on
       goto dbchek
       ;
siron   bcf portb,siren ; (7) turn siren off
       clrf beeptm
       ;
dbchek  movf igdebn     ; decrement ignition debounce if <> 0
       btfsc status,z  ; wait until debounce = 0
       goto ignsta
       ;
       decf igdebn
       goto mnloop
       ;
       ; Ignition status. Ignition switch is debounced for 4 loops.
       ;
ignsta  btfsc porta,ign ; (1) test ignition switch status
       goto igison
       ;
       ; Ignition switch is detected OFF.
       ;
       movf igchan     ; test if already detected low
       btfsc status,z
       goto chanlw     ; yes
       ;
       clrf igchan     ; flag ignition has changed to low
       movlw .6
       movwf igdebn
       goto mnloop
       ;
chanlw  movf igstat     ; test if flagged low
       btfsc status,z
       goto izfllw     ; is flagged low
       ;
       clrf igstat     ; set ignition status flag = low
       clrf icount     ; clear ignition counter
       clrf triger     ; clear trigger status
       clrf armed      ; clear system armed
       clrf tamper     ; clear tamper timer
       goto armchk     ; no need to error check
       ;
       ; Ignition is flagged low
       ;
izfllw  movf error      ; Error is flagged if arming sequence was
       btfss status,z  ; successful but sensor was triggered
       goto mnloop     ;
       ;
       ; If system is armed then do sensor check routines
       ; If ignition on timing was within limits (ONLIMIT <> 0), then
       ; wait until ignition is off for 40 loops. After this time arm
       ; system.
       ; If ignition stays off for less than 40 loops then arming sequence
       ; will abort.
       ;
armchk  movf armed      ; check system armed status
       btfss status,z
       goto syston     ; system is already armed
       ;
       movf onstat     ; if <> 0, then ignition was on within arming
       btfsc status,z  ; limits, so count loops ignition is off
       goto mnloop
       ;
       incf icount     ; ignition off count + 1
       movlw .40       ; test if 40 loops reached
       xorwf icount,w
       btfss status,z
       goto mnloop     ; no
       ;
       btfsc portb,sensor ; (1) test if sensor is triggered. If so,
       goto nosens        ; beep siren 3 times
       ;
       movlw .3
       movwf beepct
       movlw .1
       movwf beepfl
       clrf onstat     ; clear arm status
       goto mnloop
       ;
nosens  movlw 0xff      ; flag system is armed
       movwf armed
       movlw .1        ; beep siren once
       movwf beepct
       movlw .1
       movwf beepfl
       goto mnloop
       ;
       ; Ignition is detected on
       ;
igison  movf igchan     ; test if already detected high
       btfss status,z
       goto chanhi     ; yes
       ;
       movlw 0xff
       movwf igchan    ; flag ignition has changed to low
       movlw .6
       movwf igdebn
       goto mnloop
       ;
chanhi  movf igstat     ; test if flagged high
       btfss status,z
       goto izflhy     ; is flagged high
       ;
       movf armed      ; if system was armed, then disarm
       btfss status,z
       goto wasarm
       ;
sethi   movlw 0xff
       movwf igstat    ; set ignition status flag = high
       clrf error      ; clear error status
       clrf icount     ; clear ignition counter
       clrf onstat
       goto mnloop
       ;
       ; System was armed, if triggered turn siren off if on. If siren
       ; is off already, then beep twice.
       ;
wasarm  movf triger
       btfsc status,z
       goto sethi
       ;
       clrf sndebn     ; clear sensor debounce counter
       btfss portb,siren ; (7)
       goto beeptr
       ;
       bcf portb,siren ; (7)
       clrf sirenH
       clrf sirenL
       goto sethi
       ;
beeptr  movlw .40       ; set tamper timer
       movwf tamper
       goto sethi
       ;
       ; Ignition is flagged high, do on timing and checks
       ; To arm ignition must be on initially between 20 loops (1.2secs),
       ; and 60 loops (3 secs). If in between these limits then ONSTAT
       ; <> 0. Outside these limits ONSTAT = 0.
       ;
izflhy  movf armed      ; if armed was set dont increment counters
       btfsc status,z
       goto docnt
       ;
       ; Ignition has been turned on after arming. If triggered as well
       ; wait 2 secs before announcing such with 2 beeps
       ;
       movf tamper
       btfsc status,z
       goto mnloop
       ;
       decfsz tamper
       goto mnloop
       ;
       movlw .2        ; beep twice to indicate tamper
       movwf beepct
       movlw .1
       movwf beepfl
       goto mnloop
       ;
docnt   movlw .61
       xorwf icount,w  ; if on count = 61 then no more counting
       btfsc status,z  ; ignition has been on too long
       goto mnloop
       ;
       incf icount     ; ignition counter + 1
       movlw .20
       xorwf icount,w
       btfss status,z
       goto upperc     ; test if 60
       ;
       movlw 0xff      ; flag is in limits
       movwf onstat
       goto mnloop
       ;
upperc  movlw .60
       xorwf icount,w
       btfss status,z
       goto mnloop
       ;
       clrf onstat     ; flag is out of limits
       goto mnloop
       ;
       ; System is armed. Check sensor and siren status
       ;
syston  movf triger     ; if triggered check siren times
       btfsc status,z
       goto tsttrg     ; no
       ;
       movf sirenH
       btfss status,z
       goto decsir
       ;
       movf sirenL
       btfss status,z
       goto decsir
       ;
       bcf portb,siren ; (7) turn off siren
       goto tsttrg     ; siren timer = 0
       ;
decsir  decf sirenL     ; siren timers - 1
       movf sirenL,w
       xorlw 0xff
       btfss status,z
       goto mnloop
       ;
       movf sirenH
       btfss status,z
       decf sirenH
       goto mnloop
       ;
       ; Test for system trigger. Sensor is debounced for 1 loop
       ;
tsttrg  btfss portb,sensor ; (1) alarm is triggered if = 0
       goto iztrig
       ;
       clrf sndebn     ; clear sensor debounce counter
       goto mnloop
       ;
iztrig  movf sndebn     ; if <> 0 then sensor is debounced
       btfss status,z
       goto trigok
       ;
       incf sndebn
       goto mnloop
       ;
trigok  movlw 0xff      ; flag system is now triggered
       movwf triger
       bsf portb,siren ; (7) turn siren on
       movlw .4        ; set siren timers = 4b0h
       movwf sirenH
       movlw 0xb0
       movwf sirenL
       clrf sndebn     ; clear sensor debounce counter
       goto mnloop
       ;
       ;
       ;
       ;
       ;       reset vector
       ;
       ;
       org 1ffh
       ;
       goto start
       ;
       ;
       end