Chapter 9-Part2 - Merged
Chapter 9-Part2 - Merged
Pin description
𝑪𝑺 A1 A0 Selection
0 0 0 Port-A
0 0 1 Port-B
0 1 0 Port-C
0 1 1 Control Register
Application # 1: Port-A (PA0 – PA3) is connected to four switches and Port-B (PB0 – PB3) is connected to 7-segment display
driver to display decimal value of the binary information of the switches. Write an ALP program to perform the job.
.MODEL SMALL
PORTA EQU 8000H
PORTB EQU 8001H
PORTC EQU 8002H
CR EQU 8003H
.CODE
MOV DX, CR
MOV AL, 10011001B
OUT DX, AL
Start: MOV DX, PORTA
IN AL, DX
INC DX
OUT DX, AL
JMP Start
END
Application # 2: An 8255 IC is used to interface input and output devices with the 8086 microprocessor. Port-A
is connected to 8 LEDs, Port-B is connected to 8 switches and Port-C lower (PC0 – PC3) is connected to seven-
segment display. Write a program to sense the pattern of the switches, turn ON the LEDs according to same
pattern of the switches and find the number of ON Switches to show on seven-segment display.
1 turns segment ON
0 turns digit ON
.model small START:
PA equ 8060H MOV CL, 8
PB equ 8062H MOV SI, OFFSET
PC equ 8064H TABLE
CR equ 8066H MOV AL, 0FEH
TABLE DB XX L1: OUT PB, AL
DB XX MOV AH, AL
DB XX MOV AL, [SI]
DB XX OUT PA, AL
DB XX CALL DELAY ; 1
DB XX ms Delay
DB XX INC SI
DB XX ROL AH, 1
A15A14A13A12 A11A10A9A8 A7A6A5A4 A3A2A1A0 .code
1 0 X X X X X X X 1 1 0 X 00 0 = 8060H (Port-A) MOV AL, 80H MOV AL, AH
1 0 X X X X X X X 1 1 0 X 01 0 = 8062H (Port-B) OUT CR, AL LOOP L1
1 0 X X X X X X X 1 1 0 X 10 0 = 8064H (Port-C) JMP START
1 0 X X X X X X X 1 1 0 X 11 0 = 8066H (Control
Register) DELAY: MOV CX, 270
Control Word: 1000 X00X = 80 H/89H L: DEC CX
JNZ L
RET
END
Application # 4: An 8255 IC is used to interface input and output devices with the 8086 microprocessor. Port-A
is connected to stepper motor. Write a program to drive the motor on 2-phase ON mode.
Mode 1 – Handshake I/O mode or strobed I/O mode. In this mode either port A or port B can work as
simple input port or simple output port, and port C bits are used for handshake signals before actual
data transmission. It has interrupt handling capacity and input and output are latched. Example: A
CPU wants to transfer data to a printer. In this case since speed of processor is very fast as
compared to relatively slow printer, so before actual data transfer it will send handshake signals to the
printer for synchronization of the speed of the CPU and the peripherals.
Programming the 82C55: Mode 1 Strobed Input
o It causes port A and/or port B to function as latching
input devices.
o It allows external data to be stored to the port until
the microprocessor is ready to retrieve it.
o Port C is used in mode 1 operation—not for data, but
for control or handshaking signals.
o to help operate either or both port A and B as
strobed input ports
Programming the 82C55: Mode 1 Strobed Output
o The strobed output operation is similar to mode 0 output operation, except control signals are included to provide
handshaking,
o When data are written to a strobed output port, the output buffer full signal becomes logic 0 to indicate data are present
in the port latch
Programming the 82C55: Mode 1 Strobed Output
o OBF: Output buffer full goes low whenever data are
output (OUT) to the port A or B latch. The signal is set to
logic 1 when the ACK pulse returns from the external
device.
o ACK: The acknowledge signal causes the OBF pin to return
to logic 1. The ACK signal is a response from an external
device, indicating that it has received data from the 82C55
port.
o INTR: Interrupt request often interrupts the processor
when the external device receives the data via the ACK
signal. Qualified by the internal INTE (interrupt enable) bit.
o INTE: Interrupt enable is neither input nor output; it is an
internal bit programmed to enable or disable the INTR pin.
INTE A is programmed using PC6 bit. INTE B is programmed
using the PC2 bit.
Status Word for Port-C
I/O I/O IBFA STBA INTRA ACKB OBFB INTRB
.model small
.data
X DB 200 DUP(?) Print:
.code Mov si, offset X
Mov al, B4H Mov cx, N
Out FFH, al L: IN al, FEH
Mov al, 09H; BSR CW AND al, 02H
Out FFH, al JZ L
STI ; set IF Mov al, [si]
Call Keyboard Out FDH, al
Addresses and Control Word: Call Print Inc si
Port-A address: 0000 0000 1111 1100 = ; 00FC H Keyboard: Loop L
Port-B address: 00FD H Mov si, offset X END
Port-C address: 00FE H IN al, FEH
Control Register address: 00FF H AND al, 20H
Control Word: 1011 X10X = B4 H/BD H JNZ Keyboard
BSR Control Word: 0XXX 1001 = 09H for PC4 set IN al, FCH
Mov [si], al
Memory-mapped Input-Output Ports