Serial 48-key Keypad

westaust55

Moderator
I have now sorted out my compact keyboard comprising three 16 key keypads. The keypads are mounted side by side in a plastic enclosure which will also house my LCD module and other I/O devices for general experimenting.

The keypads as per the attached picture are readily available.
The encoding of these three keypads is handled by an E-Labs EDE1188 chip which can in fact handle up to 64 keys. I have built up a small board with the EDE1188 chip and necessary connectors for power, data and the keypads. See the attached photo.

The encoder chip produces a non-inverted serial data stream to the PICAXE for each keypress. The chip also does the key debouncing and has auto repeat so less code overheads for the PICAXE. The values received via the Serin command are from 0 to 63.

While there are many permutations of how the set of three keypads can be used, I have so far set them up as a psuedo PC keyboard using a lookup table in an i2c accessed EEPROM to obtained the ASCII character values corresponding to each key.

The EEPROM lookup table was written with a short program as follows:
Code:
Symbol EEPROM_1 = %10100000                       ; %1010 = EPROM, 000 = Addr/page 0, and 0 = control bit
Init:                                             ; setup i2c comms to the EEPROM
Hi2csetup  i2cmaster, EEPROM_1, i2cfast, i2cbyte  ; i2cbyte for 24LC16 and i2cword for 24LC256 EEPROM
Main:                                             ; write the keyboard data to  page 0 within the EEPROM
Hi2cout  0, ($00, $31, $32, $33, $34, $35, $36, $37 )
Pause 20
Hi2cout  8, ($38, $71, $77, $65, $72, $74, $79, $75 )
Pause 20
Hi2cout 16, ($69, $61, $73, $64, $66, $67, $68, $6A )
Pause 20
Hi2cout 24, ($6B, $7A, $78, $63, $76, $62, $6E, $6D )
Pause 20
Hi2cout 32, ($2C, $00, $00, $00, $00, $39, $30, $2D )
Pause 20
Hi2cout 40, ($3D, $00, $00, $00, $00, $6F, $70, $5B )
Pause 20
Hi2cout 48, ($5D, $00, $00, $00, $00, $6C, $3B, $27 )
Pause 20
Hi2cout 56, ($0D, $00, $00, $00, $00, $2E, $2F, $20 )
Pause 20
Hi2cout 64, ($00, $21, $40, $23, $24, $25, $5E, $26 )
Pause 20
Hi2cout 72, ($2A, $51, $57, $45, $52, $54, $59, $55 )
Pause 20
Hi2cout 80, ($49, $41, $53, $44, $46, $47, $48, $4A )
Pause 20
Hi2cout 88, ($4B, $5A, $58, $43, $56, $42, $4E, $4D )
Pause 20
Hi2cout 96, ($3C, $00, $00, $00, $00,  $28, $29, $5F )
Pause 20
Hi2cout 104, ($2B, $00, $00, $00, $00, $4F, $50, $5C )
Pause 20
Hi2cout 112, ($7C, $00, $00, $00, $00, $4C, $3A, $22 )
Pause 20
Hi2cout 120, ($08, $00, $00, $00, $00, $3E, $3F, $20 )
Pause 20
Serout 7, N2400, ( "EEPROM Writing Done." )
Pause 20
Serout 7, N2400, ( "Now test the Keypad." )
To test the operation of the keypad and corresponding lookup table I used the following code based on use of polled interrupts.

Code:
; A program to test that the characters from the 48key keypad are determined correctly
; Works with a lookup table in i2c accessed EEPROM to decode the keypad and display the correct
; character on the LCD display
;
;-------------- VARIABLES -------------
Symbol keypd =  b27
Symbol keyval = b26
Symbol shlock = b25
Symbol keychr = b24
;
;------------- CONSTANTS -------------
Symbol EEPROM_1 = %10100000                         ; %1010 = EPROM, 000 = Addr/page 0, & 0 = control bit
Symbol shiftky = 64
Symbol shftLED = 0
;
;------------- MAIN PROGRAM ----------	
init:   shlock = 0			                ; start with lowercase on keypad
        keypd = 0			                      ; start with no keypad button pressed

        Serout 7, N2400, (254,1)                    ; clear LCD screen
        Pause 20
        Serout 7, N2400, ("Welcome to my keypad")   ; an initial message

        Hi2csetup i2cmaster, EEPROM_1, i2cfast, i2cbyte  ; initialise i2c comms

        setint %00000000, %00000010                 ; set polled interrupt to act on a change to 0 on input 1 


main:  pause 10					          ; do nothing till key pressed
         goto main
;
;------------- STANDARD SUBROUTINES ----------
;
;
;------------- INTERRUPT ROUTINE -------------
;
interrupt: Serin 0, T2400, keypd                    ; here when a key is pressed
              keyval = keypd +1                        ; change 0 to 63 to 1 to 64 (easier for maths)
	 If keyval = shiftky Then                 ; if it was shift key then . . .
	    shlock = shlock ^ keyval              ; exclusive OR to toggle state of shift lock flag
	   If shlock = 0 then
	      low  shftLED                        ; disable LED when sticky SHIFT is off
	   Else 
                   high shftLED                        ; enable LED to indicate sticky SHIFT is active
	   Endif
	 Endif
	 keyval = keyval + shlock                 ; 1 to 63 for lower, 65 to 127 for upper/shifted

	 Hi2cin   keyval, ( keychr )              ; fetch the equivalent character from EEPROM table

	 Serout 7, N2400, (254,1)                 ; clear 4x20 LCD screen
              Pause 20
	 Serout 7, N2400, ("You pressed the     ")

	 If keypd    = 63 then                    ; first test for keys SHIFT, SPACE, ENTER, BACKSPACE
	  Serout 7, N2400, ("Shift")             ; SHIFT is still actioned but rest just indicate function
	Elseif keychr = 08 then
	  Serout 7, N2400, ("Backspace")
	Elseif keychr = 13 then 
	  Serout 7, N2400, ("Enter")
	Elseif keychr =32 then
	  Serout 7, N2400, ("Space")
	Else
               Serout 7, N2400,  (keychr)             ; otherwise output the character associated with the key
             Endif
	Serout 7, N2400,  ("  key.") 
	Pause 10
	Setint %00000000, %00000010               ; restore the interrupt scheme and return to main program
             Return
 

Attachments

Last edited:

westaust55

Moderator
Serial 48-key Keypad - part 2

Some further information on the 48 key keypad,
The attached diagram shows:
- the layout of the keys
- the corresponding key code from EDE1188
- the corresponding ASCII codes for the normal and shifted keys
- the wiring diagram for the connection of the keypads

Hope this project is of interest to others
 

Attachments

westaust55

Moderator
Why I built my own :)

Reasons include, but are not limited to:

1. Desire to build it myself. Where is the fun in buying when I can build my own )) - could have stuck with my old Psion Palmtop if a commercial keyboard and programmability were the key requirements.

2. Price. Mine was AUD$50 all up.

3. Size – more compact my keyboard is just 180mm (L) x 60mm(W) x ~ 20mm(H). Height includes the decoder board mounted below one keypad.
The one you mention is: Keyboard:320(L)×160(W)×14.5(H)mm

4. All-in-one approach. For portability, compact keyboard is mounted into the same box as my AXE022 (with PICAXE40X1) plus 4 x 20 LCD module and 8 x LED’s for alternate output. The box is being added to and will soon include, LDR, Pot, Ultrasonic sensor, DS18B20 Temp sensor, extra EEPROM memory, speaker, and more as time and finances allow. The overall box is 250mm(L) x 190mm(D) x 90mm(H)

5. Flexibility – I can redefine the keys at a moments notice. If I wanted a 2 user/player application then each can have a 16 key keypad each and the centre pad is spare – for example a Tic-Tac-Toe game for 2.

6. 101 other points that I haven’t got time to elaborate upon . . . . wining and dining are calling this Saturday night :)
 
Top