On Bruce's website he has an example of a sixteen key serial keypad, I am trying to modify it for my use on PortB.
On PortB using a 16f628a, I have my rows on PortB.1-3 and my Columns are 4-7, so using this particular piece which by the way works very well using it as Bruce's example shows on his web page:
FOR row = 0 TO 3 ' 4 rows in keypad
PORTB = 0 ' All output-pins low
TRISB = (DCD row) ^ $ff ' Set one row pin to output
col = PORTB >> 4 ' Read columns
IF col != $f THEN gotkey' If any keydown, exit
NEXT row
gotkey: ' Change row and column to key number 1 - 16
key = (row * 4) + (NCD (col ^ $f))
'NOTE: for 12-key keypad, change to key = (row * 3)
It had to be adjusted to compensate for for the keypad shifting left one bit
FOR row = 1 TO 3 ' I changed this since my row is actually using bit 1-3 is this correct???
'row is a variable and 1 to 3 would mean bit 1-3 correct and how can I sum up
'to account for bit 0 not being used?
PORTB = 0 ' All output-pins low
TRISB = (DCD row) ^ $fe ' I changed this to $fe so that PortB.0 will be low when the bits are flipped "^$fe"
col = PORTB >> 4 ' Read columns
IF col != $f THEN gotkey' If any keydown, exit
NEXT row
gotkey: ' Change row and column to key number 1 - 16
key = (row * 3) + (NCD (col ^ $f)) 'As noted above I am only using three rows instead of four
Either way I am coming out with duplicate numbers like key = 5 etc.
What am I doing wrong?
Thanks again
Bookmarks