UNIT 4(CONT.): PROGRAM CONTROL INSTRUCTIONS
UNIT 8: BASIC I/O INTERFACE
The Programmable Peripheral Interface(82C55)
• This is a low-cost interfacing-component.
• This has 24 pins that are programmable in groups of 12 pins.
• This can operate in 3 different modes.
• This can interface any TTL-compatible I/O device to the microprocessor.
Basic Description of the 82C55
• This has three I/O ports(labeled A,B and C) which can be programmed as group (Figure 11-18).
• Group A connections consist of port A(PA7-PA0) and the upper nibble of port C(PC7-PC4) and Group B consists of port B(PB7-PB0) and the lower nibble of port C(PC3-PC0).
• This is selected by its SC (chip select) pin for programming and for reading or writing to a port.
• Register selection is accomplished through the A1 and A0 input-pins that select an internal-register for programming or operation.
Table 11-2:I/O port assignments for the 82C55
• All the 82C55 pins are direct connections to the 80386SX except for the SC pin.
The SC pin is decoded and selected by a 74ALS138 decoder (Figure 11-19).
• The RESET input of the 82C55 initializes the device whenever the microprocessor is reset.
RESET input to 82C55 causes all ports to be setup as simple input-ports (usually mode 0 operation).
Figure 11-18:The pin-out of 82C55 PPI
Programming the 82C55
• The 82C55 is programmed through the 2 internal command-registers (Figure 11-20).
• Command-byte A programs the function of group A and B,
whereas command-byte B sets(1) or resets(0) bits of port C(only if 82C55 is programmed in mode 1 or 2)
• 82C55 can operate in following 3 modes:
i) Mode 0 (Simple Input or Output)
→ Port A and Port B are used as two simple 8-bit I/O ports and Port C as two 4-bit I/O ports.
→ Each port (or half-port, in case of Port C) can be programmed to function as simply an input port or an output port.
→ No handshaking is required; data is simply written to or read from a specific port.
ii) Mode 1 (Input or Output with handshake)
→ Handshake signals are exchanged between the microprocessor and peripherals prior to data transfer.
→ The ports (A and B) function as 8-bit I/O ports. They can be configured either as input or output ports.
→ Each port (Port A and Port B) uses 3 lines from port C as handshake signals. The remaining two lines of port C can be used for simple I/O functions.
iii) Mode 2 (Bidirectional Data Transfer)
→ This mode is used primarily in applications such as data transfer between the two computers or floppy disk controller interface.
→ Port A can be configured as the bidirectional port and Port B either in mode 0 or mode 1.
→ Port A uses five signals from Port C as handshake signals for data transfer. The remaining three lines from Port C can be used either as simple I/O or as handshake signals for Port B.
• Group B pins
→ are programmed as either input or output pins.
→ operates in either mode 0 or mode 1.
• Group A are programmed as either input- or output-pins. The difference is that group A can operate in mode 0, 1 and 2.
• If a 0 is placed in bit-position of the command-byte A, command-byte B is selected.
Fig. 11.20 Control word format of 8255 Fig. 11.21 Bit Set Reset Mode of 8255
Mode Definition and Bus Interface
FIGURE 11.20a: SEVEN-SEGMENT DISPLAY
Mode 0 Operation
LED Display Interfaced to the Microprocessor through an 82C55 PIA
• Both ports A and B are programmed as simple latched output-ports (Figure 11-21).
• Port A provides the segment data-inputs to the display and
Port B provides a means of selecting one display position at a time for multiplexing the displays.
• Example 11-10: Display messages FIRE on a 7-segment display interface.
DATA SEGMENT
Figure 11-21b:An 8-digit LED display interfaced to the 8088 microprocessor through an 82C55 PIA
An LCD Display Interfaced to the 82C55
• LCD display is a 4-line by 20-characters-per-line display that accepts ASCII code as input-data(Figure 11-22).
• The data-connections(D0-D7) are used to input display data and to read information from the display.
• There are 4 control-pins on the display :
1) VEE connection is used to adjust the contrast of the LED display 2) RS(register select) selects data(RS=1) or instructions(RS=0)
3) E(enable) must be a logic 1 for the LCD to read or write information.
4) R/W selects a read or write operation.
• In order to program the LCD, it has to be initialized by following steps 1) Wait at least 15ms after Vcc rises to 5.0V
2) Output the function set command(30H),and wait for at least 4.1 ms.
3) Output the function set command(30H) a second time, and wait for at least 100 μs.
4) Output the function set command(30H) a third time, and wait for at least 40 μs.
5) Output the function set command(38H) a third time, and wait for at least 40 μs.
6) Output 08H to display the display, and wait at least 40 μs.
7) Output a 01H to home the cursor ad clear the display, and wait at least 1.64 ms 8) Output the enable display cursor off, and wait at least 40 μs.
9) Output 06H to select auto-increment, shift the cursor, and wait at least 40 μs.
Table 11-3: Instructions for most LCD displays
Figure 11-22:The DMC-20481 LCD display interfaced to the 82C55
A Stepper Motor Interfaced to the 82C55
• A stepper-motor
→ is a digital-motor because it is moved in discrete-steps as it traverses through 360'
→ has 4 coils and an armature (Fig11-23)
→ is rotated by energizing the coils
→ is driven by using NPN Darlington amplifier pairs to provide a large current to each coil
• 82C55 provides motor with the drive-signals that are used to rotate the armature in either right-hand or left-hand direction (Figure 11-24).
• Stepper-motor can also be operated in the half-step mode, which allows 8 steps per sequence.
• Half-stepping allows the armature to be positioned at 0', 90', 180' and 270'. (The half step position codes are 11H, 22H, 44H and 88H).
• Below table shows the excitation sequences for clockwise and anticlockwise rotations.
Figure 11-23: The stepper motor showing Figure 11-24: A stepper motor interface to the 82C55 full-step operation a)45' b)135' c)225' d)315'
Example 11-16:An assembly language procedure that controls the stepper motor data segment
delay proc near ;procedure to cause delay mov bx,0ffffh
Key Matrix Interface
• Key-matrix contains 16 switches interfaced to ports A and B of an 82C55 (Figure 11-25).
• The switches are formed into a 4*4 matrix. Keys are organized into 4 rows(ROW0-ROW3) and 4 columns(COL0 -COL3).
• Each row is connected to 5.0V through a 10KΩ pull-up resistor to ensure that the row is pulled high when no push-button switch is closed.
• Port A is programmed as an input port to read the rows and port B is programmed as an output port to select a column.(For example, if 1110 is output to port B pins PB3-PB0, column 0 has a logic 1, so the 4 keys in column 0 are selected. With a logic 0 on PB0, the only switches that can place a logic 0 onto port A are switches 0-3.If switches 4-F are closed, the corresponding port A pins remain a logic 1).
Figure 11-25:A 4*4 keyboard matrix connected to an 8088 microprocessor through the 82C55 PIA
Figure 11-26:The flowchart of a keyboard scanning procedure
Example 11-17:KEY scans the keyboard and returns the key code in AL
mov dx,cr ;control register initialization mov al,90h ;portA=input portB=output
Jnz keypres ;if key pressed then goto label ‘keypres’
mov ch,04h ;assume ‘ch’ contains 1st number of 2nd row
Jnz keypres ;if key pressed then goto label ‘keypres’
mov ch,08h ;assume ‘ch’ contains 1st number of 3rd row
Jnz keypres ;if key pressed then goto label ‘keypres’
mov ch,0ch ;assume ‘ch’ contains 1st number of 4th row
Jnz keypres ;if key pressed then goto label ‘keypres’
jmp again jc yes ;if carry(1) generated then key found so return to main program inc ch ;else search ‘1’(key) in remaining bits
dec bh jnz rpt
yes: ret ;return to main program scan endp