Keyboard Interfacing with Ports

A common method of entering programs into a microcomputer is through a keyboard which consists of a set of switches. Basically, each switch will have two normally open metal contacts. These two contacts can be shorted by a metal plate supported by a spring as shown in Fig. 6.46. On pressing the key, the metal plate will short the contacts and on releasing the key, again the contacts will be open. The processor has to perform the following three major tasks to get meaningful data from a keyboard.

A key actuation is sensed by sending a low to all the rows through port- A. Pressing a key will short the row and column to which it is connected. So, the column to which the key is connected will be pulled low. Therefore, the columns are read through port-B to see whether any of the normally high columns are pulled low by a key actuation. If they are, then rows can be checked individually to determine the row in which the key is down. For checking each row, the scan code of the type shown in Table is output to port -A one by one. This process of sensing a key actuation is called keyboard scanning.

A key press has to be accepted only after debouncing. Normally, the key bounces for 10 to 20 milliseconds when it is pressed and released. The bouncing time depends on the type of key. When this bounce occurs, it may appear to the microcomputer that the same key has been actuated several times instead of just one time. This problem can be eliminated by scanning the row in which the key press is deducted after 10 to 20 milliseconds and then verifying to see if the same key is still down. If it is, then the key actuation is valid. This process is called key debouncing.

    1. Sense a key actuation.
    2. Debounce the key.
    3. Decode the key.

The three major tasks mentioned above can be performed by the software when a keyboard is connected through ports to the 8085 processor. Consider a simple keyboard in which the keys are arranged in rows and columns as shown in Fig. The rows are connected to port-A lines of 8255 and the columns are connected to port-B lines, of the same chip. The rows and columns are normally tied high. At the intersection of a row and column, a key is placed such that pressing a key will shorten the row and the column.