; William Grill 08/26/98 ; Riverhead Systems ; P.O. Box 621954 ; Littleton, CO. 60162-1954 ; ednlock.asm ; GPIO equ 6 STATUS equ 3 PC equ 2 INDR equ 0 #define ZERO STATUS,2 #define CARRY STATUS,0 #define pw 4 bit equ 8 #define errordet bit,0 #define debounce bit,1 #define active bit,2 #define flash bit,3 #define intest bit,4 temp equ 9 key equ 0A last equ 0Bh cnt equ 0C timout equ 0D alarmcnt equ 0E temp1 equ 0F ; begin clrw ; * movlw 03Bh ; initialize tris GPIO movlw 08F ; set long timeout, disable wakeup on delta OPTION btfsc STATUS,pw ; test source of reset goto init ; power reset begin1 btfsc intest goto start btfss errordet ; test if error sequence active goto start decfsz alarmcnt ; test if error sequence done goto start4 bcf errordet movlw 03Bh ; disable alarm tris GPIO goto start1 setflash movlw 2Bh ; assert flash output tris GPIO bsf flash movlw 8C ; set flash delay w/o wakeup OPTION bsf GPIO,4 retlw 0 init ; provide full power up reset btfsc STATUS,7 goto begin1 movlw 8F ; set long timeout, disable wakeup, enb pullup OPTION movlw 4 movwf GPIO movlw 03Bh tris GPIO movlw 5 movwf timout movwf alarmcnt clrf bit goto start keytable ; canned sequence table addwf PC ; 1-key,2-key2,4-key3 retlw 0 ; dummy retlw 1 ; last key retlw 2 retlw 4 ; combination is 1-1-4-2-1 retlw 1 retlw 1 ; first key start4 movlw 01Bh ; enable alarm output tris GPIO movlw 20 ; alternate alarm output xorwf GPIO movlw 08D ; set alarm timeout, disable wakeup on delta, enb pullup OPTION sleep start clrf GPIO btfss flash ; test if following a key release goto start1 bcf flash movlw 5 ; set up for reset after # of long delays +1 movwf timout start1 decfsz timout goto start2 incf timout clrf bit ; clear all flags start2 movfw GPIO ; read keys movwf temp1 iorlw 0F4 xorlw 0FF movwf temp btfss ZERO ; test if any key is asserted goto a ; null detected movlw 0F ; set long delay /w wakeup on delta, enb pullup OPTION btfsc active ; test if key was active call setflash ; set up flash and flash delay bcf debounce bcf active sleep ; goto f1 ; * a ; key found movlw 5 ; set up for reset after # of long delays +1 movwf timout btfss debounce ; test if already serviced goto ba movfw temp xorwf last,w ; provide debounce compare btfsc ZERO goto c movfw temp ; save for next debounce test movwf last goto rest ba bsf debounce ; set debounce flag and save movfw temp ; save for next debounce test movwf last rest movlw 08 ; set short delay /w wakeup on delta, enb pullup OPTION sleep ; goto f1 ; * c ; service the detected key clrf key btfsc last,3 ; test key 3 goto key3 btfss last,0 ; test for key 2 goto key2 key1 bsf key,0 btfsc active ; test if already serviced goto rest goto starttest key2 bsf key,1 btfsc active goto rest goto starttest key3 bsf key,2 btfsc active goto rest starttest bsf active btfsc intest ; test if first key in sequence goto start3 movlw 5 ; **set # entries in lock sequence** movwf cnt bsf intest ; start3 movfw cnt call keytable ; get correct sequence entry xorwf key ; compare with detected key btfss ZERO bsf errordet e decfsz cnt ; test if all entries made goto rest bcf active bcf intest bcf debounce btfss errordet ; qualify if error in entries goto setoutput ; error detected movlw 1Bh ; enable output tris GPIO movlw 0A ; init pulse sequence movwf alarmcnt bsf GPIO,5 ; assert alarm movlw 08D ; set alarm pulse timing, disable wakeup, enb pullup OPTION bsf errordet ; set process flag sleep ; setoutput bsf GPIO,2 ; assert output movlw 08F ; set output delay, w/o wakeup, enb pullup OPTION sleep end