Shop OBEX P1 Docs P2 Docs Learn Events
12 Key Keypad interface... — Parallax Forums

12 Key Keypad interface...

ArchiverArchiver Posts: 46,084
edited 2001-05-30 12:03 in General Discussion
Hello Stampers,
This is'nt a sales pitch, but it may be a help to somebody.
If anyone is interested, I have a 12 key keypad interface available to connect to the stamp.
The interface requires 5 lines to run, but is smoother to use than a serial keypad
as the stamp can simply look at 1 input to see if a key has been pressed, and if not it can move onto other things. This is smoother than 'serin"wait"' commands with a serial keypad interface.
The interface chip is an SX28. The SX28 continually scans the keypad, and directly enters the data into a·4 bit port on the stamp,·no data type conversion of the bits is necessary, as the SX28 loads the stamp port in binary form. If you are interested at all, email me off list, or see below for sample code to suit bs2 / bs2e / bs2sx / bs2p. I will have a bs1 sample available in the next few days.
The chip is $22 Australian incl tax.· Chip details below.
If the sample code below looks wierd by the time you get it, email me and I'll send you the original stamp program off list.
Regards, Chris
Email....
fes@gateway.net.au

SX28...
28 pin device, requires 5 i/o lines to the stamp. No external parts are required with the SX28 chip except a few resistors and a decoupling cap for the power input.

=======SAMPLE CODE======
'Keypad28, program by Chris Anderson.
'Sample program for connection of basic stamp (bs2p in this example) to
'SX28 keypad scanner. Connect the 5 lines as shown at the end of this program.

'·NOTE, 12 KEY KEYPADS ONLY

·'Setup i/o's.
dirs = %0000000000100000·'0 = input, 1 = output

·'Setup variables
looper var byte···'Variable declaration, 2 bytes, 16 bits
counter var word···'Variable declaration, 2 bytes, 16 bits
timeout var word···'Variable declaration, 2 bytes, 16 bits
value var nib···'Variable declaration, 1 nibble, 4 bits

·'Setup constants
lcd con 5··'Pin 5 goes to serial lcd display, at 9600 bps with bs2P

reset_point:·'Start point of the program
·serout lcd,16624,[noparse][[/noparse]254,1,254,128,"Keypad28"]·'send to lcd display
·debug cls, "Keypad28"·'send to pc screen in download cable connected
·counter = 0···'reset counter variable to zero
·timeout = 0···'reset timeout variable to zero
loopstart:
·if IN4 = 1 then loopstart·'IN4 is the key pressed indicator pin
·for looper = 0 to 5··'set to loop thru 5 times only
cycle:
·timeout = timeout + 1··'add 1 to timeout variable
·if timeout = 20000 then reset_point·'reset if timed out
·if in4 = 1 then cycle··'return to 'cycle:' if key not pressed
·timeout = 0····'reset timeout to zero, key has been pressed
·value = ~ INA···'invert the bits from the SX18 and put them into the 'value' variable
·if value = 10 then cancel_key·'if cancel pressed then goto cancel key routine
·if value = 12 then enterpressed·'if Enter pressed then go to routine for 'Enter' key
·gosub process_key····'process the key pressed
·serout lcd,16624,[noparse][[/noparse]254,1,254,128,dec counter]·'send to lcd display
·debug cls, dec counter··'send to pc screen
·pause 200·'pause for 0.2 seconds
·next·····'start loop again
·goto reset_point···'go to reset if 6 key presses
enterpressed:
·serout lcd,16624,[noparse][[/noparse]254,1,254,128,"Enter"]·'Enter key routine
·debug cls, "Enter Key Pressed"
·'PUT YOUR CODE HERE FOR AN ENTER KEY PRESS
·pause 2000
·goto reset_point
cancel_key:
·serout lcd,16624,[noparse][[/noparse]254,1,254,128,"Cancel"]·'Enter key routine
·debug cls, "Cancel Key Pressed"
·'PUT YOUR CODE HERE FOR A CANCEL KEY PRESS
·pause 2000
·goto reset_point
process_key:··'Add correct amount to Counter variable
·if looper > 0 then x_10·'if not first key press, go to x_10
·counter = value·'if first key press then counter = value
·return··'return to scanning routine
· x_10:···'multiplication routine
·counter = counter * 10 + value·'multiply 'counter' * 10 and then add the last keypress
·return··'return to scanning routine


'··This example uses a simple 12 key keypad.

'··Change stamp pin allocation to suit yourself if you like,
'·but don't forget to change the setup at the start of the program to suit.

'·STAMP TO SX28
'Pin 5 (i/o 0) of stamp to pin 10 (rb0) of SSX28 via 470 ohm resistor.
'Pin 6 (i/o 1) of stamp to pin 11 (rb1) of SSX28 via 470 ohm resistor.
'Pin 7 (i/o 0) of stamp to pin 12 (rb2) of SSX28 via 470 ohm resistor.
'Pin 8 (i/o 0) of stamp to pin 13 (rb3) of SSX28 via 470 ohm resistor.
'Pin 9 (i/o 0) of stamp to pin 17 (rb7) of SSX28 via 470 ohm resistor.

'·SX28 POWER PINS
'Pin 2 of the SX28 to 5 Volts +
'Pin 4 of the SX28 to o Volts - (Ground).
'Pin 28 to +5 Volts via 10K resistor. (This is the reset pin, if you
'connect it to zero volts, it resets the SX28.)
'Note, put a 0.1uF capacitor across pin 2 and 4 above.
'Note, the SX28 does not require an external resonator / oscillator.
'Leave pins 3, 5, 11, 12, 13, 26 and 27 un-connected, and take any other pins
'to ground via 4.7K resistors.
'
'·KEYPAD TO SX28 ·'See keypad documentation for keypad pinouts
'Keypad Row A to SX28 pin 23 (rc5)
'Keypad Row B to SX28 pin 18 (rc0)
'Keypad Row C to SX28 pin 19 (rc1)
'Keypad Row D to SX28 pin 21 (rc3)
'Keypad Column 1 to SX28 pin 22 (rc4)
'Keypad Column 2 to SX28 pin 24 (rc6)
'Keypad Column 3 to SX28 pin 20 (rc2)

'·Keypad layout...

'·(C = Column)>·C1·· C2·· C3

'··Row A >>>·· |[noparse][[/noparse]1]· [noparse][[/noparse]2]· [noparse][[/noparse]3]|·

'··Row B >>>·· |[noparse][[/noparse]4]· [noparse][[/noparse]5]· [noparse][[/noparse]6]|

'··Row C >>>·· |[noparse][[/noparse]7]· [noparse][[/noparse]8]· [noparse][[/noparse]9]|

'··Row D >>>·· |[noparse][[/noparse]*]· [noparse][[/noparse]0]· [noparse][[/noparse]#]|

'·Program treats [noparse][[/noparse]*] as Cancel , and [noparse][[/noparse]#] as Enter.

'Note, the 'Counter' Variable can only count to 65535, so values over
'this amount will roll over and display strange numbers. Keep this in
'mind when writing your code.


Sign In or Register to comment.