keypad software help please

Tim Vukman

New Member
I have basically lifted the code below from http://www.rev-ed.co.uk/docs/chi008.pdf and I am trying to scan a 4x4 keypad. In the "scan" section, only the last key_value routine seems to work.

For example, as is, only the key_value = 12 routine works. If I comment out the key_value = 12 section, then the key_value = 8 routine is the only one that works.

The keypad is wired such that the rows each have a 10k resistor to ground. The input pins connect on the keyboard side of these same resistors. The rows each have an output port of their own.

The source code is below. I would really appreciate any ideas on how to have all 4 of the key_value blocks active at the same time so that I can just retrieve the key number for the key pressed and move on.

CODE

'keypad interface routine
'picaxe 28x clock project

symbol key_value = b1
'captures the key number pressed

scan:
'set outputs high in sequential order

key_value = 0
'starting point for row0
pins = %00000001
'set to high to provide voltage to keypad row3
gosub key_test
'test the input pins for which column the key is in

key_value = 4
'starting point for row1
pins = %00000010
'set to high to provide voltage to keypad row2
gosub key_test
'test the input pins for which column the key is in

key_value = 8
pins = %00000100
'set to high to provide voltage to keypad row1
gosub key_test

key_value = 12
pins = %00001000
'set to high to provide voltage to keypad row0
gosub key_test

debug
'watch key number in b1

goto scan
'keep repeating the scan module

key_test:
if pin1 = 1 then add1
'to input pin for row3 (highest) leg 12

if pin5 = 1 then add2
'to input for row2 leg 16

if pin6 = 1 then add3
'to input for row1 leg 17

if pin7 = 1 then add4
'to input for row0 (lowest) leg 18

return 'close the gosub in "SCAN" module

add4: key_value = key_value + 1
'id keys 13, 14, 15, 16
add3: key_value = key_value + 1
'id keys 9, 10, 11, 12
add2: key_value = key_value + 1
'id keys 5, 6, 7, 8
add1: key_value = key_value + 1
'id keys 1, 2, 3, 4

return
'won't run without this one
 

Rickharris

Senior Member
Well done - some times a bit of time, though and effort yeald the best results - and just look at what you learned by doing that!
 
Top