cblock 0x20
SaveKeyPress
endc
Start:
banksel TRISIO
movlw ~(1<<GP1)
movwf TRISIO
Getkey:
banksel GPIO
movlw ~(1<<GP3) ;make GPIO,3 high
movwf GPIO
btfss GPIO,GP3 ; if button pressed (GP3 low)
movf SaveKeyPress ;saves key press ? I think. I know it set it
goto Getkey ;to f7 in mplab sim but is this right?
end
do_if_nokey
nop ;?????
Getkey:
movfw GPIO
andlw b'11101' ;check for GP0,GP2,GP3,GP4 note: GP1 set as output
bz do_if_nokey ;no keypressed go back
[COLOR="RoyalBlue"]
;if had one or more key pressed
[/COLOR]
movwf SaveKeyPress ;saves key press
[COLOR="RoyalBlue"]
; check multi key at one say check GP0 & GP2
[/COLOR] movfw SaveKeyPress
andlw b'00000101' ;get GP0,GP2 mask
xorlw b'00000101' ;Is both key pressed (GP0 and GP2 go high)
btfsc STATUS,Z
call Multi_Key_pressed
[COLOR="RoyalBlue"]
;check key one by one[/COLOR]
btfsc SaveKeyPress,GP0 ; if button pressed (GP0 high)
call Keypressed
btfsc SaveKeyPress,GP2 ; if button pressed (GP2 high)
call Keypressed
btfsc SaveKeyPress,GP3 ; if button pressed (GP3 high)
call Keypressed
btfsc SaveKeyPress,GP4 ; if button pressed (GP4 high)
call Keypressed
goto Getkey
Multi_Key_pressed
nop
Keypressed
nop
return
Getkey:
banksel GPIO
movlw b'001111' ;makes GP5-4 outputs GP0-3 inputs
movwf GPIO
btfss GPIO,GP0 ;input is high skip if low put a 0 in SaveKeypress
ADDCF SaveKeyPress ;?how do I move the 0 to SaveKeyPress
btfss GPIO,GP1 ;input is high skip if low put a 0 in SaveKeypress
????
btfss GPIO,GP2 ;input is high skip if low put a 0 in SaveKeypress
????
btfss GPIO,GP3 ;input is high skip if low put a 0 in SaveKeypress
????
movf SaveKeyPress
btfss GPIO,GP0 ; if button pressed (GP0 low)
bsf sGPIO,GP0 ; move to shollow copy
btfss GPIO,GP1 ; if button pressed (GP1 low)
bsf sGPIO,GP1 ; move to shollow copy
btfss GPIO,GP2 ; if button pressed (GP2 low)
bsf sGPIO,GP2 ; move to shollow copy
btfss GPIO,GP3 ; if button pressed (GP3 low)
bsf sGPIO,GP3 ; move to shollow copy
movfw sGPIO ;get state of keys
movwf SaveKeyPress ;save them
cblock
KeyBuffer:4
Keys
Previous
endc
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
andlw 0x0f ;keep only 0-3 bits [COLOR="Blue"]<-added[/COLOR]
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
;here KeyBuffer will contain 4 key values.
Also called a ring buffer.How many keystrokes do you want to buffer? It's often called a circular buffer.
cblock
key:4
endc
GetKey
movfw GPIO ;no keypressed input pin=0
andlw b'00001111' ;Mark every input key GP0-GP4
bz GetKey ;loop until keypressed
return
Save_new_key
call GetKey ;Setkey 1
movwf key
call GetKey ;Setkey 2
movwf key+1
call GetKey ;Setkey 3
movwf key+2
call GetKey ;Setkey 4
movwf key+3
;savekey to EEProm
Check_if_key_in_order
;getkey from EEProm if needed
call GetKey ;Check Key 1
andwf key,W ;get only bit of key[]
xorwf key,W ;is key press
bnz Wrongkey
call GetKey ;check key 2
andwf key+1,W ;need result to Wreg
xorwf key+1,W
bnz Wrongkey
call GetKey ;check key 3
andwf key+2,W
xorwf key+2,W
bnz Wrongkey
call GetKey ;check key 4
andwf key+3,W
xorwf key+3,W
bnz Wrongkey
All_keys_Match
; all key match do what you want
nop
Wrongkey
nop
;wrong key try again or stop
I'll try it that way It looks better then what I came up with. If it was a stamp I be done
but it would of cost me $50.00 for the stamp. I like the $1.10 for the 12f683 I'm going to get this assembly language one bit at a time maybe lol thanks all
I'll try it that way It looks better then what I came up with. If it was a stamp I be done
but it would of cost me $50.00 for the stamp. I like the $1.10 for the 12f683 I'm going to get this assembly language one bit at a time maybe lol thanks all
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'
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?