Keyboard Interfacing with 8086 using 8255
A keyboard is one of the most common input devices for a microprocessor-based system. It allows the user to enter data, commands, or instructions in a convenient and user-friendly way. However, a keyboard is not directly compatible with the microprocessor, and it requires some interfacing circuitry and software to communicate with it. In this article, we will discuss how to interface a keyboard with the 8086 microprocessor using the 8255 programmable peripheral interface (PPI) chip.
What is 8255 PPI?
The 8255 PPI is a general purpose I/O device that can be used with many different microprocessors. It has 24 I/O pins that can be individually programmed in two groups of 12 and used in three major modes of operation: mode 0 (basic input/output), mode 1 (strobed input/output), and mode 2 (bi-directional bus). The 8255 PPI also has a control word register that determines the configuration and operation of the I/O pins. The internal architecture of the 8255 PPI is shown below:
![8255 Internal Architecture]()
The data bus buffer is a bi-directional 8-bit buffer that interfaces the 8255 PPI to the system data bus. It transfers data or control words between the microprocessor and the 8255 PPI. The read/write and control logic manages the internal and external transfers of data and control words. It accepts inputs from the CPU address and control buses and issues commands to both of the control groups. The port select signals (A0 and A1) are used to select one of the three ports (A, B, or C) or the control word register. The chip select signal (CS) enables the communication between the 8255 PPI and the CPU. The read signal (RD) allows the CPU to read data or status information from the 8255 PPI. The write signal (WR) allows the CPU to write data or control words into the 8255 PPI. The reset signal (RESET) initializes the control register to 9Bh and sets all ports to input mode.
How to interface a keyboard with 8086 using 8255?
There are different types of keyboards available, such as hexadecimal, alphanumeric, or matrix keyboards. In this article, we will focus on interfacing a matrix keyboard with the 8086 microprocessor using the 8255 PPI. A matrix keyboard consists of a number of keys arranged in rows and columns. Each key is connected to a row line and a column line. When a key is pressed, it connects its row line to its column line, creating a unique combination that can be detected by scanning the rows and columns.
The following figure shows how a 3x8 matrix keyboard can be connected to two ports of the 8255 PPI:
The rows of the matrix are connected to four output port lines (PA0-PA3) of port A, while the columns are connected to eight input port lines (PB0-PB7) of port B. Port C is not used in this example. The port A lines are configured as outputs, while the port B lines are configured as inputs with internal pull-up resistors. The control word for this configuration is 80h, which sets mode 0 for both ports.
The algorithm for scanning the keyboard is as follows:
- Initialize port A as output and port B as input by writing 80h to the control word register.
- Write FFh to port A to make all row lines high.
- Read port B and check if any column line is low. If yes, go to step 4. If no, go to step 7.
- Write FEh to port A to make PA0 low and keep other row lines high.
- Read port B and check which column line is low. The combination of PA0 and PBx indicates which key is pressed in row 0.
- Repeat steps 4 and 5 for PA1-PA3 by writing FDh, FBh, and F7h respectively to port A.
- Go back to step 2 until all keys are scanned.
The following table shows the key codes for each key in the matrix:
| PA/PB | PB0 | PB1 | PB2 | PB3 | PB4 | PB5 | PB6 | PB7 |
|---|
| PA0 | 00h | 01h | 02h | 03h | 04h | 05h | 06h | 07h |
| PA1 | 08h | 09h | 0Ah | 0Bh | 0Ch | 0Dh | 0Eh | 0Fh |
| PA2 | 10h | 11h | 12h | 13h | 14h | 15h | 16h | 17h |
| 1Fh The article is not finished yet. Here is the next part: Once the key code is obtained, it can be used to perform various tasks, such as displaying the corresponding character on a monitor, storing it in a memory location, or sending it to another device. For example, the following assembly code snippet shows how to display the key code as a hexadecimal digit on a seven-segment display connected to port C of the 8255 PPI: |
;Assume that the key code is stored in AL register MOV AH, AL ;Copy AL to AH AND AL, 0Fh ;Mask the lower nibble of AL MOV BL, AL ;Copy AL to BL SHR AH, 4 ;Shift the upper nibble of AH to lower nibble MOV CL, AH ;Copy AH to CL MOV DX, 0FF88h ;Set the address of port C OUT DX, BL ;Output BL to port C (lower digit) INC DX ;Increment DX to point to control word register MOV AL, 0E4h ;Set the control word for port C (upper digit) OUT DX, AL ;Output AL to control word register DEC DX ;Decrement DX to point to port C OUT DX, CL ;Output CL to port C (upper digit)
The above code assumes that the seven-segment display is connected as follows:
The control word for port C is 0E4h, which sets PC7-PC4 as outputs and PC3-PC0 as inputs. The lower digit is displayed on PC3-PC0 and the upper digit is displayed on PC7-PC4. The following table shows the output values for each hexadecimal digit:
| C The article is not finished yet. Here is the next part: | 0Eh |
How to download the PDF file of this article?
If you want to download the PDF file of this article, you can use the following link: [Download PDF]. This link will take you to a website where you can view and download the PDF file of this article for free. You can also print the PDF file or share it with others.
Conclusion
In this article, we have learned how to interface a keyboard with the 8086 microprocessor using the 8255 PPI. We have discussed the features and functions of the 8255 PPI, the circuit diagram and algorithm for scanning the keyboard, and the code for displaying the key code on a seven-segment display. We have also provided a link for downloading the PDF file of this article. We hope that this article has been helpful and informative for you.
The article is already finished. There is nothing more to write. If you want to read the article again, you can scroll up or download the PDF file. If you have any questions or feedback, please let me know. ? The article is already finished. There is nothing more to write. If you want to read the article again, you can scroll up or download the PDF file. If you have any questions or feedback, please let me know. ? 6500f7198a