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:
To test the operation of the keypad and corresponding lookup table I used the following code based on use of polled interrupts.
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." )
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
-
26.9 KB Views: 77
-
111.1 KB Views: 114
Last edited: