Data

Fig 1. A simple hardware-encoded (ASCII) keyboard interface

/THIS SUBROUTINE SEN SES A KEY CLOSURE 0*1 M

/ASCII KEYBOARD A* ID TH£J 1N PUTS THE EIGHT-BIT

/PARALLEL ASCII KEY CODE«

KEY!«/ IM /X7PUT THE DATA WORD THAT COVTAIVS

0Q 1 /THE STATUS HIT FDR THE ASCII KEYBOARD

AMI /SAVE O^JLY THE STATUS BIT FOR

00 1 /THE KEYBOARD

JZ /JU1P bACK TO KfcYIM IF THE STATUS bIT

KEYI^J /IS L ERO, btCAUSE MO KEY IS PRESSED 0

IV /A KEY IS PRESSED- SO ItfPUT THE

000 /ASCII CODE IV TO A

AVI /SET THE Parity bIT TO

177 /A LOGIC ZERO

RET /AJD THEN RETURN TO THE CALLING PROGRA'1

is a logic zero (no key is pressed), the A register will contain zero as a result of the ANI instruction and the J2 (jump on zero) instruction to KEYIN will be executed. When a key is pressed, bit DO of the A register will be a logic one after the first IN instruction is executed. As a result of the ANI instruction, the JZ to KEYIN will no longer be executed. Instead, the second IN instruction will be executed, which will cause the code for the key that is pressed to be read into the A register. This instruction also causes the keyboard's flag to be cleared The keyboard flag must be cleared before the 8080 calls the KEYIN subroutine again, so that the 8080 does not sense that the same key is pressed. Remember, the key has only been pressed once. After the key code is input, the second ANI instruction sets the parity bit (D7) of the code to a logic zero. This means that the programs that call KEYIN can be used with keyboards that generate odd parity, even parity, or no parity.

Another type of keyboard that is often used with microcomputers is a scanned keyboard. This type of keyboard, like a multiplexed display, requires very little interface hardware but requires a large amount of software. Typically, scanned keyboards are used in calculators, microwave ovens, singleboard microcomputers, and low-cost microcomputer-based games. The interface for a 16-key keyboard, arranged as four columns of four keys, is shown In Fig. 3. The software that causes the 8080 to scan the keyboard and generate a unique code for each key is listed in Fig. 4. This software has to perform many of the functions that were previously performed by the hardware-encoding logic. For instance, the software must (1) sense a key closure, (2) de-bounce the key closure, (3) determine which key is pressed, (4) generate a unique key code for the key that is pressed, (5) wait for the key to be released,

DATA d2

0 0

Post a comment