|
||
MATRIX KEYPAD SUPPORTDEFINITIONS
HARDWAREMany applications of the TDS2020F computer module involve input from a keypad. Sometimes a full alphanumeric keyboard is required. Other uses involve inputs from microswitches or relay contacts. All of these requirements can usually be met by means of the keypad-encoding scheme built in to the TDS2020F as a combination of special hardware and software. The diagrams indicate the connections for up to 64 keys. Although this is shown as an 8 x 8 matrix you may choose to use only part of it, e.g. 4 x 4 to input from a hex keypad. Alternatively the switches may represent microswitches etc. and not buttons. Port B is used for the keypad. Even if all the keys are not there you cannot use spare bits of Port B for other purposes. The 8 pull-down resistors shown on the data bus lines are needed only for the keypad and all 8 must be present even if the keypad is not using all the data lines. A lower value is recommended when using certain LCDs on the bus, see ALPHANUMERIC LCDS, page 100. Leads to the keypad should be kept as short as practicable, preferably under 300mm (12 inches). If they are too long wrong codes can result but the bus can be buffered with a 74HC245 device if needed, see EXTENDING THE BUS, page 303. The diodes indicated are Schottky types for their low forward voltage drop. 1N4148 types will work but with reduced noise immunity. When using the keypad mode in an application do not use chip select CS81B0* for any other purpose since this is used to internally strobe the output of Port B in the key matrix. SOFTWAREIf a key is kept closed during multiple calls of NEWKEY only the first time will show which is pressed. Later ones give n=0. This is the word that is used most. The scheme works as follows. A single 1 is put in turn to each of the 8 outputs from Port B. However the keypad words put Port B into a special mode under which these outputs do not appear at once. They only occur if the processor calls address hex 81B0. Eight times in succession a different pattern is put to Port B and then address 81B0 is read. One row of the matrix is scanned each time and a pattern showing which switches are closed is input to the microprocessor. Software decodes these 8 patterns to give the number of the key. If more than one key is pressed the highest number is returned. Typical times for execution of the keypad words are:
INKEY 17�s
Here are some tips on using the keypad support words. The first example is a word that waits until a key is pressed. In function this is similar to KEY on the serial input:
: KEY ( - n ) \ Wait for key, n=1 to 64
The word REGULAR is included to show that you can have the computer do many other jobs while waiting for a key. Define REGULAR to include whatever else the machine must do all the time, but keep it to a maximum of 100ms execution time so that response to a key is not delayed. Usually you really need a value associated with each key, which is not just the simple key number. For example on an alphanumeric keypad the ASCII code will be wanted. The conversion is best done using a look-up table in this way:
HEX CREATE CODES \ Look-up table : TRANSLATE ( n1 - n2 ) \ Change key code n1 into n2
In this example the particular codes chosen for each key are arbitrary, the actual content of the table will depend on the application. The final example combines the previous two and puts the code generated, assumed to be in ASCII, on an LCD. See LIQUID CRYSTAL DISPLAYS, page 97, for further details.
: REQUEST ( - )
\ Input from key matrix to LCD and PAD
We escape from the word REQUEST only when the key that translates to code 0D (ASCII for carriage return) is pressed. The message typed out is put to the LCD and also is left in the PAD for further processing by the program. |