You are on page 1of 8
Chapter 9 | PERIPHERAL INTERFACING with typical peripheral devices such as hexadecir DMA controller, printer, CRI (Cathode Ras and coprocessor. 9.1 BASICS OF KEYBOARD AND DISPLAY INTERFACE TO A MICROPROCESSOR: A commen method of entering programs into 4 microcomputer is via a keyboard. A popular way of displaying reatlts by the micracomputer is by . using seven segment displays. The main fi 1s v0 be performed for interfacing a keyboard are 1. Sense a key actuation. 2. Debounce the ke 3. Decode the key. JLet us now elaborate on the keyboard interfacing concepis, 4 keyboard is arranged in rows and columns. Figure 9.1 shows a2 x 2 keyboard imerfaced to a typical microcomputer. In Figure 9.1, the columns are normally ata HIGH level. A Rey actuation is sensed by sending a LOW to each raw one at a time via PAO and PAI of port A. The nvo columns can then be input via PB2 and PBS of port B to sce whether any of the nortnally | HIGH columns are pulled LOW by a key actuation. If they are, the rows 835 836 Peripheral Interfacing Chapter 9 i San bs checked individually to determine the row in which the key is down, The tow and column code in which the key is pressed ean thus be found. icracamputer Pa Powa | rai FIGURE 9.12 » 2 beyboardimerficed te a microcomputer The Dest step is to debounce the key. Key bounce occurs when a key 3 prossed of released — it bounces for a short time before making the Soatict. When this bounce occurs, it may appear ts the microcomputer that the same key has bccn actuated several tines instean of just once, This problem can be eliminated by reading the keyboard sfics 2) menu then ‘ering to sce if iis still down. IFicis, chen the key acauation's tore The NES step is to trantlate dhe cow and cofumn code int 2 ane | popelbr code such es hexadecimal or ASCIT. This can easily be accom, plished by a program, ‘There are certain characteristics associated with Keyboard actuations Tih must be considered while interfacing a microcomputer. Typically, these are two-key lockout and N-key rollover, The two-key lackoon takes imo account only oe key pressed, An additional key pressed and seleased Basics of Keyboard and Display Interface 837 docs not generate any codes. The system is simple to implement and most ‘often used. However, it might slow down the typing since each key must ‘he fully released before the next one is pressed down. On the other hand, the N-key rollover will ignore all keys pressed until only one remains down. Now let us claborate on the interfacing charactoristies of typical dis plays. The following functions are to be ypically performed for displays 1. Queput the appropriate display code. _ 2. Ouepur the code via right entry or left entry into the displays if there is more than one display. The above fonctions can easily be realized by a microcomputer pro. gram. If there is more than one key, they are typically arranged in rows. A row of four displays is shown in Figure 9.2. Note chat in Figure 9.2, one has the option of ourputting the display code via right entry of left entry. Ific is entered via left enery, then the code for the most significant digit of the four-digit display should be output first, then the next digit code, and so on. Note that the first digit will be shifted three times, the next digit twice, the next digit once, and the last digit (least significant digit in this case} does not need to be shifted. The shifting operations are so fast that viseally all four digits ~will appear on the display simuhtancously. If the displays are entered via right entry, then the least significant digit must be ‘output first and the rest of the sequence is similar to the left entry. eet el ee FIGURE 9:24 cow of four Boplans. Two techniques are typically used to interface 2 hexadecimal display to the microcomputer. These arcnonmultiplexed and multiplexed. Innonmul- tiplexed methods, cach hexadecimal display digit is interfaced to the micro- compater via an 1/O port. Figure 9.3 illustrates this method. ‘BCD to seven-segment conversion is donc in software. The microcom- puter can be programmed 10 output to the tre display digits in sequence. ‘However, the microcomputer executes the display instruction sequence so fast that the displays appear to human eyes at the same time. Figure 9.4 ilustrarcs the multiplexing method of amterfacing the "wo hexadecimal displays to the microcomputer. 838 Peripheral Interfacing Pet Microcompaee S| 7 FICURE 9.3 Nowmiuhipowed hexatacimal dys, Pom Pon Microcomputer FIGURE 9.4 Muliplesed displays re ae re simultaneously. However, the segment to be illuminated is The keyboard and display interfacing concepts described here can be realized by either software or hardware. In order to relieve the micropro- cessor of thes¢ functions, microprocessor manufacturers have developed a number of keyboard/display controller chips such 2s the Intel 8279. These OI Basics of Keyboard and Display Interface 839 ‘ships are typically initialized by the microprocewor. The keyboard /display fanctions are then perfocined by the chip independent of the microproces- sor. ‘The amount of keyboard /disptay functions performed by the control- Ter chip varies from onc manufscmrer to another. However, these hunetions are usually shared between the controller chip and the microprocessor. 9.1.1 HEXADECIMAL KEYBOARD/DISPLAY INTERFACE TO THE 8085 In order to illustrate the hexadccimal keyboard /display interfacing concepts, the 8083/8155/2716-based microcomputer of Figure 2.32 will be utilized. The 1/0 map of the microcomputer is provided in the fallow- ing: sR ose Por A 09H Port B OAH Por C OBH The 2716 and 8156 memory maps are provided in the following: 2716 Memory Map (0000H through O7EFHL 8156 Memo Q800H through OSFFH Figure 9.5 shows the microcomputer’s interface to a hexadecimal Keyboard and two seven segment hexadecimal displays. ‘The Keyboard contains a 4 x4 mawrix keypad. There are cight 10K sesistors which connect all columns and rows of the keypad to 5 vols such that all bits of port A will be HIGH when no Key is activated, The display incindes two hexadecimal displays {TTL311). The TIE3LIs have on-chip decoders A look-up table will be used to store sow and columa codes for cach hexadecimal digit in the 2716 EPROM. In the software, port Ais first read and checked to determine whether the previous key has bee released. This will climinate any problem when someone holds the key for a long time. When the key is released, it is debounced by calling a subroutine providing 2 20-ms delay. The 8156 RAM will be used as the stack, The program will then input the rows and columns of the keyboard via port A and cheek for key closure. TF the key Peripheral Intezfacing 340 Ada ; ue torn Fenopy 0 aevan asia) MU RC 96 AHL ZEA LY SUMED | . eerkaoooiop! pas ‘sst4/ suc rssoe vied | “LEEEEL EE ig | ey “EFEE 104 or Basics of Keyboard and Display Interface 841 closure is sensed, it is debounced again by waiting 20 ms, and the binary sede comesponding to the key pressed is determined by using the look-up ‘able. Rows and columns arc connected wo input port A. Port Cis config ured as an output port. The rows are also connected 10 port C. The rows are grounded by sending zeres to all rows via port C and key closure is sensed by inputting the cofmnn dara via port A In order to display the keyin data, all displays are cleared fire. The least significant display is the first kevin data and is stored at memory location O800H. When the second key is pressed, the first data is displayed in the Jeft display and the sccond dita is displayed on the right display, The second display is also stored in location O800H. When the third key is pressed, the lelt-_mosc display is discarded. The sccond key from location O800H is displayed in the left display and the third Key is displayed on the fight display. The third kcy is also stored in location O800H and the process continues: The assembly language program listing is given in Figure 9.6. ‘The data in TABLE of Figure 9.0 are obtained by inspecting the keys of Figure 9.5. For example, the code for the E key is 1011 OL11,, This is because when a LOW is sent on the top row and the E key is pressed, the top row and the column connected to bit 6 of port A (normally HIGH solumn is grounded by activating the E key) becomes zero. This makes port A data B7,,. Similarly, the codes for the other keys in TABLE can be determined. 1 oe Quo 2 PORTA eQuooH 3 PORTE equoaH 4 PORT EQUOEH 5 START = MAOH, ©: Gonigure Pot A at 6 ourese 2 Input, Pons 8 8 Cas outputs 7 UMS 08AOH > Inliaien a MVIA oroH —;Setupclplay 9 OUTPORTE =; Tobe secs 0 Nor 5 Delay atc 1 VIA, OOH > Enable both latch fines 2 QUTPORTE =; Tedisplay zeros B ‘sta aecoH ‘Sore daptayed dat in + Tocation aso FIGURE 3.6 Assembly language program for hex keyboard and deploys, 842 Peripheral Interfacing a a 8 x” 40 a 2 3 REPEAT KevareN Kercost NeXT ROW orcove Next Chapter 9 MPAA case, our pone See rraetneoat ieponra 2) Inga fem 8 cororaet Compare with FOL INEKEY OPEN Rivage are cps 7 Tyethoraiee Wait fo previous fey 0 gen CALL DEROUNCE ; Belay 20m6 IN FORA nou Foma rtoroH Comore with FOH wreev cist Check or Sey chore GAUL GEROUNCE | Delay 20m MMVIALOPTH 3 SerAtroal ones ORs 5 Clear ary Rat 2 Retatezeroto fist ow MOV,B,A Sove row maski 8 ouTeORTC Srp all rows IN PeTA Ingato and corm MOVE. A Save rw and column code Ant fant Mask row code crore ‘Gheck colar for HIGH Fz DECODE W2=0, decode tay sic Z=1, hey nt toune MOV A.B Move enete rest DMP NeXT ROW row on, TARE oad saning acess a lookup tbe ona 8, oF ‘able character courser MovA.C ‘Geto and column cade owren Compare row and column swith lookup table Je-vore Hey found, go1m DONE na 2 ma increment Ht, acre > Dectement character couniee FIGURE 9.6 comtinsed.

You might also like