Microprocessor Systems Design

1 Overview
The purpose of this final experiment is to enable you to use the development board to control and monitor simple peripherals, in this case a Keypad/Display Unit, accessible via an 8255 Peripheral Interface Adapter. As you can see from Section 3.2, you are expected to prepare some source code before this lab.

2 Expanding the I/O with the 8255 Device
Inside the Keypad/Display Unit is an 8255 device. The 8255 contain three 8 bits ports A, B and C that we can connect or not to the system data bus D. The three ports can be programmed in input or output. In the case of output, all ports are their output latch/buffer. There are three basic modes of operation that can be selected by the system software:
Mode 0 – basic input/output
Mode 1 – strobed input/output
Mode 2 – bi-directional bus

When the reset input goes “high” all ports will be set to the input mode with all 24 port lines held at a logic “one” level by the internal bus hold devices. After the reset is removed the 8255 can remain in the input mode with no additional initialization required. This eliminates the need for pull-up or pull-down devices in “all CMOS” designs. During the execution of the system program, any of the other modes may be selected by using a single output instruction.

The modes for Port A and Port B can be separately defined, while Port C is divided into two portions as required by the Port A and Port B definitions as shown in Table 1. All of the output registers, including the status flip-flops, will be reset whenever the mode is changed. Modes may be combined so that their functional definition can be “tailored” to almost any I/O structure. For instance; Group B can be programmed in Mode 0 and Group A could be programmed in Mode 1.

Table 1: 8255 Mode Selection

In our application, we want to program the ports as follows: port A, B and C7-C4 in output and C3-C0 as input. So, according to the datasheet, after a reset, we must send the control word #81h. This is shown in Table 2. This table also shows the port selection details.

Table 2: 8255 Control Register Values and Port Addressing

3 Keypad and Display Application
By now, you will be expected to have a good understanding of the 8255 operation as well as the operation of the 8051 device. Further information is available in the course textbook.

This final part of the experiment is concerned with reading input from a small keypad and then displaying the data on a simple multiplexed seven-segment display. Both of these modules are accessed via an 8255 Peripheral Interface Adaptor (PIA) IC as described in Section 2. A block diagram of the system is shown in Figure 1 and an actual image of the expansion board is provided in Figure 2.

Figure 1: Block Diagram for Keypad and Display Interfacing

Figure 2: Actual Keypad and Display Interface Module

3.1 Background to Keypad and Display Interfacing
To employ keypads for data entry with a limited number of I/O lines a multiplexed arrangement, such as shown in Figure 3, is common. With reference to this schematic, consider the sequence of steps that a microcontroller must take in order to determine if a particular key is pressed. In this case assume the microcontroller is directly connected to the “R” row outputs and “C” column inputs. Also assume that the C inputs are weakly pulled low by resistors that are not shown.

Figure 3: Block Diagram for Keypad Interfacing

To detect whether a key has been pressed the following actions must be taken in sequence:
• The row outputs are driven high, i.e. “1111”bin, and column values are read
• If the columns read = “0000”bin then no keys are being pressed as the inputs are pulled low by the resistors. However, if any column reads = “1” then a key has been pressed, overriding the weak pull-down resistor. The column containing the “1” also indicates that the key concerned is one of the four keys along that particular column. The next step is to determine which of these four keys is being pressed as follows:
• The microcontroller drives ONLY one row at a time to the “1” state whilst reading the column values; that is the row outputs will be set to “0001”bin then to “0010”bin, “0100”bin and “1000”bin
• When row containing the pressed key is set to “1” the column outputs will contain a value other than “0000”bin.

3.1.1 Controlling the Keypad via the 8255
As the 8051 has only a limited number of port pins, when external memory addressing is used, an 8255 device is employed to expand the I/O. The keypad is connected to Port C of the 8255 with the upper nibble of Port C connected to the row lines (outputs) and the lower nibble of Port C connected to the columns (inputs). Writing a whole byte to Port C will not affect the lower nibble (configured as inputs). Similarly reading a byte from Port C will not affect the upper nibble, configured as outputs. However, it would be normal to mask out the bits that you do not wish to impact any subsequent value tests. This is usually achieved with the ANL instruction.

The 8255 is automatically reset when the supply power is applied. In addition, its Chip Select (CS) line is tied low so that the device is permanently enabled. To appropriately configure Port C of the 8255, you must first setup the 8255 Control Register with the necessary bit values. The Control Register (CR) is accessible when the device’s a1 and a0 are set to “11”bin. CR must be programmed so that the upper nibble of Port C acts as an output, whilst the lower nibble pins of Port C are inputs. Port C is accessible when a1 and a0 are set to “10”, respectively.

3.1.2 Controlling the Display via the 8255
The display schematic is provided in Figure 4. It comprises four seven-segment displays. Port A is wired in parallel to the a,b,..,h segment pins of each of these display devices. The lower nibble of Port B is then used to select which of the four displays is active at a given time. The displays have no integral memory and so changing the active display will simply cause the same segment information to be displayed on the currently selected device(s).

Figure 4: 8255A to Display Interface

To allow the four display elements to display dissimilar information “at the same time” we can make use of the human eye’s persistence of vision. The concept operates as follows:

Four registers within the 8051 are used to hold the numerical value / segment code for their corresponding display segment. Each of the four display devices is selected in turn. Whilst a given display is active, its unique segment code is written to the segment lines causing the appropriate value to be displayed. When the next display device is selected, its display code is used instead. Once all four displays have been illuminated in this fashion, the cycle repeats.

If this operation takes place fast enough, it appears that all four displays are continuously illuminated, each with their appropriate numerical value.

3.2 Preparing your Assembly Language Source Code – BEFORE the LAB
Example pseudo code to control the multiplexed display is given in Appendix 1. You are EITHER required to extend this program OR to create an alternative assembly language program to perform the following actions:

1) Periodically write the contents of the R0 (right most digit), R1, R2 and R3 Bank0 registers to the display. The contents of these registers hold the segment code for the corresponding decimal character such that if the value of the right-most digit is 3 decimal, the R3 register holds the segment code to display a “3” character.

2) Scan the keypad for any single key press. If pressed the key that is pressed must be identified and its numerical value used to ensure the left-most digit displays the correct value of this key. This applies to the keys “0..9” and “A..E”.

3) Upon each key press the value of each displayed digit must be shifted to the right. The most significant value is discarded when it is updated with the value shifted in from the adjacent display digit to its right. As the value of the digits are held in the registers R0, R1, R2 and R3, the contents of these registers must be adjusted according to corresponding sequence of actions:

New R3 <= Old R2
New R2 <= Old R1
New R1 <= Old R0
New R0 <= Segment code for new key pressed.

4) The numerical value of the keypad keys should be arranged as shown in Figure 5:

Figure 5: Keypad Layout

5) The keypad should include a debounce mechanism, as necessary and the display must be programmed so as to provide flicker-free illumination of the characters held in the R0, R1, R2 and R3 registers.

6) At any time, if the “F” key is pressed the content of the registers R0..R3 should be returned to their null value such that the display is blank. Key presses will then be shown as entered from the left of the display, as before.

Sample Solution