cblock 0x20
KeyBuffer:4
Keys
Previous
sGPIO
d1
d2
lock
lock1
lock2
lock3
lockopen
SaveKeyPress
endc
org 0x0000 ; org sets the origin, 0x0000
goto Start ; go to beginning of program
org 0x0004 ;interrupt vector
goto Start
Start
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
clrf ANSEL ; digital I/O
movlw b'1110101'
movwf OSCCON ;8MHz internal oscillator
movlw b'001111'
banksel TRISIO
movwf TRISIO
banksel GPIO
clrf GPIO
clrf Previous
movlw KeyBuffer
movwf FSR
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
if Keys==0xB ;If config==0xB is true,
banksel GPIO ;set to bank 0 GPIO
bsf GPIO,GP5 ;make led come on GP5
goto Main ;let main program run
else
goto KeyLoop ;if not a mach go back and cheack buffer
endif
;here KeyBuffer will contain 4 key values.
Main: ; what happens when you get it unlocked
Delay10mS ; delay W x 10ms
;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
END ; directive 'end of program'