WaitNoKey call Delay10 ;required for debounce
movfw SWITCH_PORT ;get keys
movwf tmp1 ;im using pull up res's so active low. not sure if this is ;right way to go about it
comf tmp1, W
andlw 0x1f ;keep only bottom 5 bits
btfss STATUS,Z ;are any keys pressed
goto WaitNoKey ;yes, so carry on waiting
clrf Keys ;indicate no key pressed
WaitValid call Delay10 ;wait 10mS for debounce
movfw Keys ;gets keys from last time
movwf OldKeys ;keep copy for later
movfw SWITCH_PORT ;get new key state
movwf tmp2
comf tmp2, w
andlw 0x1f ;keep only bottom 5 bits
movwf Keys ;save for next time around
xorwf OldKeys,w ;keep only keys that have changed
andwf OldKeys,w ;and were pressed last time around
btfsc STATUS,Z ;will be non zero if a key was released
goto WaitValid
movfw OldKeys ;contains the valid key combination
movwf validkeypress ;store valid keypress in reg,.,
call checkchar
waitnopress movfw SWITCH_PORT ;= skip if set ;) - z set if theres a match
xorlw 0x3f ;bit mask with 111111
btfss STATUS, Z ;so if there is a match, and no buttons are pressed, z is set
goto waitnopress ;skips the next instruction and goes back to the beginning.......
goto WaitNoKey