Tuesday, December 11, 2012

CGKEYCHIP1 Custom Keypad Example



The Maximite design uses a PS/2 connection as a keyboard interface. You can use a full keyboard connected to either a CGCOLORMAX1 or the CGMMSTICK1.
If you want to embed either of these two setups into a project, you might choose to replace the full keyboard with something either more compact or custom for your application. The CGKEYCHIP1 wired into a “ColorMax” or “stick” lets you create your own keyboard by adding your own buttons.
The CGKEYCHIP1 is a 24 pin chip in a DIP (through-hole) package. Four wires connect to the Maximite that include ground, power, and the two PS/2 communication signals (data/clock). You can wire in twelve distinct buttons for the keyboard keys plus three “modifier” buttons.
The CGKEYCHIP1 has two sets of keys that it can transmit:

Set1
Set2
F1
Up Arrow
F2
Down Arrow
F3
Left Arrow
F4
Right Arrow
F5
Space Bar
F6
Page Up
F7
Page Down
F8
Enter
F9
End
F10
Home
F11
Tab
F12
Backspace


An input pin on the chip selects between these sets of keys.
The CGKEYCHIP1 runs off of the 5V that the PS/2 connection provides. Both chip grounds should be connected to ground. The pins marked “NoConnect” should not be connected to anything.
Supplied with the CGKEYCHIP1 is a 1.3 kohm resistor that has to be connected from pin 11 to pin 15 for the chip to operate correctly
The PS/2 data signals are open-collector signals. When you connect the GCKEYCHIP1 to a CGCOLORMAX1 there are pull up resistors already on the ColorMax. When you connect to a CGMMSTICK1 and CGVGAKBD1 combination, the CGVGAKBD1 board already has pull up resistors in place for the two PS/2 lines. No additional resistors are needed in this case.

When you connect the CGKEYCHIP1 to just a CGMMSTICK1, you will need to attach two pull-up resistors in order to have the chip function correctly. Each of the two PS/2 lines should be pulled to 5V through a 10 kohm resistor.
The SetSelect input to the CGKEYCHIP1 selects the key set that you wish to use, either set 1 or set 2. Connecting this input directly to 5V will select set 1, while connecting this input to ground selects set 2.
The key inputs are activated by momentary contact to ground. Simple SPST buttons can be used.


You can write a very simple MMBasic program to check the codes that the keys transmit against the list of codes found in this document:
do
a$ = inkey$
if a$ <> "" then
print asc(a$)
endif
loop




When run, set 1 will return these codes:
Key
Plain
Control
Shift
Shift+Control
F1
145
209
177
241
F2
146
210
178
242
F3
147
211
179
243
F4
148
212
180
244
F5
149
213
181
245
F6
150
214
182
246
F7
151
215
183
247
F8
152
216
184
248
F9
153
217
185
249
F10
154
218
186
250
F11
155
219
187
251
F12
156
220
188
252






Set 2 returns these codes :
Key
Plain
Control
Up Arrow
128
192
Down Arrow
129
193
Left Arrow
130
194
Right Arrow
131
195
Space Bar
32
0
Page Up
136
200
Page Down
137
201
Enter
13
13
End
135
199
Home
134
198
Tab
9
9
Backspace
8
8


MMBasic interprets the Alt as a key by itself, not a modifier. The keycode for the Alt key is 139, Control-Alt is 203, Shift-Alt is 171, Control-Shift-Alt is 235. This program will return two key codes when Alt is used, first the Alt code, then the key code. Control-Shift-Alt-F1, for example, returns 235 241.












Purchase a CGMMSTICK1 Download of Maximite Integrated Development Environment: MMIDE


No comments:

Post a Comment