Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

DAN136

Interface to a Radio Shack 270-215 Keypad

  By Michael Simpson

I first came across this keypad a couple of years ago.  Back then it cost about $20.   However its selling now for around $7.99.  It has 15 keys that are mapped in a matrix.  The membrane can be written on as well.

I'm going to create a simple library so that you can add one to your next application.

3 / 5 4/4 6/2   Key
X     5/3 1
  X   5/3 6
    X 5/3 11
X     7/1 2
  X   7/1 7
    X 7/1 12
X     8/0 3
  X   8/0 8
    X 8/0 13
X     2/6 4
  X   2/6 9
    X 2/6 14
X     1/7 5
  X   1/7 10
    X 1/7 15

The Above matrix is used to generate the keys.  Note that I show the pin/port combos the pin is the pin number on the keypad connector.  The port is the IO port it is connected to.   The combos were setup this way so the connector would match up with ports 0-7.

Here I show a simple hookup to a DiosChip 28.  The connection is the same for all the Dios product lines.

 

Here I show the right angle header I used for connecting the keypad connector to a breadboard.

Here you can see the connector connected to DiosChip 28

Here connected to a Dios Module

Connection to Dios Ultra

 

The following program demonstrates the library commands.   It actually contains the library commands.  Note that you could just include the library.

Program 1 Download it here

'Interface to Radio Shack 270-215 Keypad
func QuickRSkeypad()

dim key
  RSkeypadinit()

loop:
  key=RSkeypadread()
  if key <> 0 then
     print key
   endif
   goto loop

endfunc

'--------------------------------------------------
'Sets up ports for key pad.
'Hardcoded to port 0-7 because of pullups
func RSkeypadinit()
   'Set up ports
   output 2,4,5
   input 3,1,0,6,7

   'Now build custom port
   CUSTOMBIT0 = 3
   CUSTOMBIT1 = 1
   CUSTOMBIT2 = 0
   CUSTOMBIT3 = 6
   CUSTOMBIT4 = 7

   'Set weak Pullups on ports 0-7
   pullupon
   endfunc

'-------------------------------------------------
'Tests the keypad
'Returns 0 if no key press
'Returns key 1-15 depending on key
func RSkeypadread()
   dim pdat,res
 

'First matrix line
   high 2,4,5
   low 5
   customportget pdat
   pdat = pdat & 31 ^ 31

   lookdown res,pdat,1,2,4,8,16
   if res > 0 then
      exit res
   endif

'2nd matrix line
   high 2,4,5
   low 4
   customportget pdat
   pdat = pdat & 31 ^ 31

   lookdown res,pdat,1,2,4,8,16
   if res > 0 then
     exit res + 5
   endif

'3rd matrix line
   high 2,4,5
   low 2
   customportget pdat
   pdat = pdat & 31 ^ 31


   lookdown res,pdat,1,2,4,8,16
   if res > 0 then
     exit res + 10
    endif

   exit 0
endfunc
 

A little information about the program.  Three pins are set for output.  2,4,5  They are accessed sequentially and set low one at a time the remaining pins 0,1,3,6,7 are mapped using the customeport command.   This process allows us to test the keys on each leg of the matrix.

Using the lookdown command we can then return the key code for the corresponding matrix match.

 

I had the need for a simple 4 pin binary output for the key pad.   I used the Dios32pin module to do this.  By using a 6 wire cable I provided the 4 output bits and 2 power pins.

Program 2 Download it here

'Interface to Radio Shack 270-215 Keypad (4bit output)
func main()
   dim key

   low 12,13,14,15
   output 12,13,14,15
   low 12,13,14,15

   RSkeypadinit()

loop:
   key=RSkeypadread()
   LATC = key
   goto loop


endfunc

include \lib\DiosRSkeypad.lib

 

Here is an example on using the hardware UART to output the data.  Only pin 9 TXdata and power leads are needed.

Program 3 Download it here

'Interface to Radio Shack 270-215 Keypad (Serial Output)
func main()
   dim key,flag
   clear
   hsersetup baud,HBAUD115200,txon,start

   RSkeypadinit()

loop:
   key=RSkeypadread()
   if key <> 0 then
     hserout key
     flag = 1
   else
     if flag = 1 then
        hserout 0
        flag = 0
     endif
    endif

   goto loop


endfunc

include \lib\DiosRSkeypad.lib

 

Parts list

DiosPro 40 Pin Chip

Dios Workboard Deluxe

 

Easy RS232 Driver  

DiosPro 28 Pin Chip

Dios 32 Pin Carrier (Carrier #1)

 

9 Pin Cable

Breadboard Regulator

 

Copyright © 2001 - 2007 Kronos Robotics