how to get the keypad to work

tiscando

Senior Member
I was always trying to get the vsm keypad to work both ends, and here is the solution: to use the bi-directional pins of a 28x1 (40x1) for keypads with up to 8 pins
so, for example, the picaxe's input (or portc) pins are in 2 groups of 4, one with pins 0-3 is 'phase 1' and connects to one side of the keypad, and the other with pins 4-7 is 'phase 2' and connects to another side of the keypad.
see the attachment for a sample schematic which goes with the code below. oh, and the resistors need to be set to the digital primitive for the keypad to work. also, make sure that one phase is set to inputs at the same time or before the other phase becomes high outputs.

Code:
start:
let pins=0
let dirsc=%11110000 'phase 1
high portc 4,5,6,7
main1:
if portc pin0=0 and pin1=0 and pin2=0 and pin3=0 then goto main1 'wait for a keypad button press
pause 1
if portc pin0=1 then
	b2=1
elseif portc pin1=1 then
	b2=2
elseif portc pin2=1 then
	b2=3
elseif portc pin3=1 then
	b2=4
else 
	goto start
endif
let dirsc=%00001111 'phase 2
high portc 0,1,2,3

if portc pin4=1 then
	
elseif portc pin5=1 then
	b2=b2+4
elseif portc pin6=1 then
	b2=b2+8
elseif portc pin7=1 then
	b2=b2+12
else
	goto start
endif
'example of sending keypad data in serial to the serial terminal set to 2400 baud:
serout 0, t2400, (#b2,", ") 
waitin:
if portc pin4=1 or pin5=1 or pin6=1 or pin7=1 then waitin 'wait for button to be released
goto main1
 

Attachments

Last edited:
Top