Microprocessor and Interfacing II - Lecutre Notes
Microprocessor and Interfacing II - Lecutre Notes
Lectures Notes
Interfacing
When we discuss interfacing, We are interested in 2 things:
Designing logic circuits (hardware) and writing instructions (software) to enable the
microprocessor to communicate with peripherals (I/O devices).
Types of I/O
The microprocessor identifies the peripherals based on their interfacing technique either as:
• Memory-mapped
A peripheral is connected as if it were a memory location.
It is identified with a 16-bit address.
Data transfer is implemented using memory-related inst.
• Peripheral-mapped
A peripheral is identified with an 8-bit address.
The microprocessor uses special instructions to implement data transfer.
Microprocessor-controlled data transfer can take place under five different conditions:
• Unconditional
• Polling (Status check)
• Interrupt
• With READY signal
• With Handshake signal
1. Unconditional:
The microprocessor assumes that the peripheral is always available.
For example, displaying data at LED port involves simply enabling the port, transfers data, and
going to execute the next inst.
3. Interrupt
When a peripheral is ready to transfer data, it sends an interrupt signal to the microprocessor.
The microprocessor stops executing the program, accepts/sends the data from/to the
peripheral, and then return to the program.
End of Part 1
2 Interrupts
Introduction
The interrupt I/O is a process of data transfer whereby an external device or a peripheral can
inform the processor that it is ready for communication and it requests attention.
The process is initiated by an external device and is asynchronous, meaning that it can be
initiated at any time without reference to the system clock. However, the response to an
interrupt request is directed or controlled by the microprocessor.
The interrupt requests are classified in two categories: maskable interrupt and nonmaskable
interrupt. More specifically four maskable interrupts and one nonmaskable interrupt. Among
these four maskable interrupts, one is nonvectored. The other three are vectored to specific
locations
RST 7.5
1 Non-
Vectored TRAP
maskable
If the flip-flop is enabled and the input to the interrupt signal INTR (pin 10) goes high, the
microprocessor is interrupted. This is a maskable interrupt and can be disabled.
DI (Disable Interrupt):
1-byte instruction.
Resets the Interrupt Enable flip-flop and disables the interrupt.
It should be included in a program segment where an interrupt from an outside source cannot
be tolerated.
Step 2: When the microprocessor is executing a program, it checks the INTR line during the
execution of each instruction.
Step 3: If the line INTR is high and the interrupt is enabled, the microprocessor:
• Completes the current instruction
• Disables the Interrupt Enable flip-flop
• Sends a signal called INTA - Interrupt Acknowledge (active low).
• The processor cannot accept any interrupt requests until the interrupt flip-flop is
enabled again.
Step 4: The signal INTA is used to insert a restart (RST) instruction through external hardware.
• The RST instruction is a 1-byte CALL instruction that transfers the program control to a
specific memory location on Page 00H (The first 256 bytes).
Step 6: Assuming that the task to be performed is written as a subroutine at the specified
location, the processor performs the task. This subroutine is known as a service routine
Step 7: The service routine should include the instruction EI to enable the interrupt again.
Step 8: At the end of the subroutine, the RET instruction retrieves the memory address where
the program was interrupted and continues the execution.
RST Instruction
The 8085 instruction set includes
eight RST (Restart) instructions:
• RST 0 , ………., RST 7
• These are 1-byte Call instructions
that transfer the program execution to
a specific location on page 00H, as
listed in the following Table.
Implementing the RST instruction (STEP 4)
To implement Step 4 in the interrupt process, insert one of these instructions in the
microprocessor by using external hardware and the signal INTA.
The microprocessor checks INTR, one clock period before the last T-state of an instruction cycle.
In the 8085, the Call instructions require 18 T-states; therefore, the INTR pulse should be high at
least for 17.5 T-states.
In a system with 3 MHz clock frequency the input pulse to INTR should be at least 5.8 µs long.
(1/3MHz *17.5)
3. Can the microprocessor be interrupted again before the completion of the first interrupt
service routine?
The answer to this question is determined by the programmer.
After the first interrupt, the interrupt process is automatically disabled.
If instruction El is written at the beginning of the routine, the microprocessor can be interrupted
gain during the service routine.
The following Figure shows how this circuit can be used with a Tri-
state buffer to implement an interrupt priority scheme.
Function Table for the priority encoder
When an interrupting
device requests service,
one of the input lines
goes low, which makes
line E0 high and
interrupts the
microprocessor
These last four (RSTs and TRAP) are automatically vectored (transferred) to specific locations
on memory page 00H without any external hardware.
They do not require the INTA signal or an input port; the necessary hardware is already
implemented inside the 8085.
TRAP
A nonmaskable interrupt that has the highest priority among the interrupt signals.
It need not be enabled, and it cannot be disabled.
As shown from this schema, all of the interrupts can be masked entirely by EI, or individually by
the SIM instruction and its code.
Triggering Mechanism
RST 7.5 Triggering Level
This is positive-edge sensitive and can be triggered with a short
pulse. The request is stored internally by the D flip-flop until
the microprocessor responds to the request or until it is
cleared by Reset or by bit D4 in the SIM instruction.
PENDING INTERRUPTS
Because there are several interrupt lines, when one interrupt request is being served, other
interrupt requests may occur and remain pending.
The 8085 has an additional instruction called RIM (Read Interrupt Mask) to sense these pending
interrupts.
Summary
Restart as a software instruction
After the breakpoint routine, the program should return to executing the main program at the
breakpoint.
The breakpoint procedure allows the user to test programs in segments.
For example, if RST 6 is written in a program, the program execution is transferred to location
0030H; it is equivalent to a 1-byte call instruction. This can be used to write a software
breakpoint routine.
Illustrative Program:
This code illustrates the use of a procedure to display the accumulator content and the PSW into
PORT1 and PORT2 when A is entered through a keyboard, and then returns when 0 is entered.
Here when an interrupt with an RST 6 code is initiated, this procedure is called. Arguably, this
could also be called from within a program as a normal instruction
SP’ X
So if at any at any point the programmer desires to view the content of the accumulator within
the program for debugging purposes, the user/programmer could inject RST 6 within the code.
Additional I/O Concepts and Processes
The 8085 interrupt I/O, described earlier, is limited because of its single interrupt pin and
hardware requirements to determine interrupt priorities.
To circumvent these limitations, a programmable interrupt controller such as the 8259A is used
to implement and extend the capability of the 8085 interrupt.
Another I/O process, Direct Memory Access (DMA), is commonly used for high-speed data
transfer.
• One of the major limitations of the 8085 interrupt scheme is that all requests are vectored to
memory locations on page 00H, which is reserved for ROM or EPROM,
• Access to these locations is difficult after a system has been designed.
• In addition, the process of determining priorities is limited, and extra hardware is required to
insert Restart instructions.
• The 8259A overcomes these limitations and provides many more flexible options.
• It can be employed with 16-bit Intel microprocessors as the 8086/8088 as well.
3 General-Purpose Programmable
Peripheral Devices
The 8255A Programmable Peripheral Interface
The 8255A is a widely used, programmable, parallel I/O device.
It can be programmed to transfer data under various conditions, from simple I/O to interrupt
I/O.
It is flexible, versatile, and economical (when multiple I/O ports are required).
It is an important general-purpose I/O device that can be used with almost any microprocessor.
Block Diagram
Block Diagram
CS Hex
Selection
A7 A6 A5 A4 A3 A2 A1 A0 Address
100000 0 0 80H A
100000 0 1 81H B
100000 1 0 82H C
100000 1 1 83H Control Register
Communication Steps
To communicate with peripherals through the 8255A, three steps are necessary:
1. Determine the addresses of ports A, B, and C and of the control register according to
the Chip Select logic and address lines A0 and A1.
2. Write a control word in the control register.
3. Write I/O instructions to communicate with peripherals through ports A, B, and C.
Operation Modes
Mainly there are two main Modes, BSR Mode, and I/O Mode.
I/O Mode
The I/O mode can be activated by setting D7 to 1, the rest of the control word can specify
the detailed configuration for each port.
Keep in mind that there are 2 Groups and 3 Ports, A,B, and C.
C contains 2 sub Ports, CLower, and CUpper. They are configured differently, but addressed
with the same address
Control Groups
Port B
Group B
CLower
I/O
CUpper
Group A
Port A
Mode 0
Simple Input/output configuration
Example: Mode 0
Given the Following circuit, write a program to input from Port B and Port C L, the output to Port
A and CU
Things we need to do:
Input from B , Output to A
Input from CL , Output to CH
Solution:
Step 1) Configure the Ports Addresses (Memory Addressing)
From the hardware configuration, we know that the port addresses are as following:
A15 A14 A13 A12 A11 A12 A11 A0 A7 A6 A5 A4 A3 A2 A1 A0 Add
Port A 1 X X X X X X X X X X X X X 0 0 8000H
Port B 1 X X X X X X X X X X X X X 0 1 8001H
Port C 1 X X X X X X X X X X X X X 1 0 8002H
CR 1 X X X X X X X X X X X X X 1 1 8003H
A range of addresses can be used, we’ll adopt the following:
Port A = 8000H
Port B = 8001H
Port C = 8002H
Control Register = 8003H
Mode 1
Input or Output with Handshake
Applies to Group A, and Group B
In Mode 1, handshake signals are exchanged between the MPU and peripherals prior to data
transfer. The features of this mode include the following:
Two ports (A and B) function as 8-bit I/O ports. They can be configured either as input or
output ports.
Each port uses three lines from port C as handshake signals. The remaining two lines of
port C can be used for simple I/O functions.
Input and output data are latched.
Interrupt logic is supported.
Note: to enable INTE for Port A, and Port B, we need to access the control Register through the
BSR Mode. It is later discussed
The status word can be read from Port C, we are mostly interested in the IBF Latch at D 5 and D1
which specifies whether data is available
This word is meant only to be Read, other information include interrupt availability and the
status of the Interrupt latch enable INTE
Programming Notes
There are two programming models for operation in Mode 1
Note: to enable INTE for Port A, and Port B, we need to access the control Register through the
BSR Mode. It is later discussed
The status word can be read from Port C, we are mostly interested in the IBF Latch at D 5 and D1
which specifies whether data is available
Example: Mode 1
The following Figure shows an interfacing circuit using the 8255A in Mode 1. Port A is designed
as the input port for a keyboard with interrupt I/O, and port B is designed as the output port for
a printer with status check I/O.