ch2 - Lec4 - Interfacing Peripherals - 3 - Int

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Microprocessor and

Interfacing
Ch2_lec4_ Interrupts and
Interrupt Response

Kassahun Tamir 1
Interrupt and Interrupt Response
 An 8086 interrupt can come from any one of three
sources.
 One source is an external signal applied to the nonmaskable
interrupt (NMI) input pin or to the interrupt (INTR) input pin. An
interrupt caused by a signal applied to one of these inputs is
referred to as a hardware interrupt.
 A second source of an interrupt is execution of the Interrupt
instruction, INT. This is referred to as a software interrupt.
 The third source of an interrupt is some error condition produced
in the 8086 by the execution of an instruction. An example of this
is the divide-by-zero interrupt.

Kassahun Tamir 2
Interrupt and Interrupt Response
 At the end of each instruction cycle, the 8086 checks to
see if any interrupts have been requested. If an
interrupt has been requested, the 8086 responds to the
interrupt by stepping through the following series of
major actions.
 It decrements the stack pointer by 2 and pushes the
flag register on the stack.
 It disables the 8086 INTR interrupt input by clearing the
interrupt flag (IF) in the flag register.

Kassahun Tamir 3
Interrupt and Interrupt Response
 It resets the trap flag (TF) in the flag register.
 It decrements the stack pointer by 2 and pushes the
current code segment register contents on the stack.
 It decrements the stack pointer again by 2 and pushes
the current instruction pointer contents on the stack.
 It does an indirect far jump to the start of the
procedure.

Kassahun Tamir 4
Interrupt and Interrupt Response

Kassahun Tamir 5
Interrupt and Interrupt Response
 In an 8086 system. the first 1 Kbytes of memory, from
00000Hto 0003FFH, is set aside as a table for storing
the starting addresses of interrupt service procedures.
 The starting address of an interrupt service procedure is
often called the interrupt vector or the interrupt pointer,
so the table is referred to as the interrupt-vector table
or the interrupt-pointer table.

Kassahun Tamir 6
Interrupt-Vector Table

Kassahun Tamir 7
Divide-by-zero Interrupt Type 0
 The basic output interface receives data from the
microprocessor and must usually hold it for some
external device.

 When the OUT instruction executes, the data from AL or


AX are transferred to the latch via the data bus.

Kassahun Tamir 8
Single-step Interrupt Type 1
 When you tell a system to single-step, it will execute
one instruction and stop.
 when in single step mode, a system will stop after it
executes each instruction and wait for further direction
from you.
 If the 8086 trap flag is set, the 8086 will automatically
do a type 1 interrupt after each instruction executes.

Kassahun Tamir 9
Nonmaskable Interrupt Type 2
 The 8086 will automatically do a type 2 interrupt
response when it receives a low-to-high transition on its
NMI input pin.
 When it does a type 2 interrupt, the 8086 will push the
flags on the stack. reset TF and IF, and push the CS
value and the IP value for the next instruction on the
stack.

Kassahun Tamir 10
Breakpoint Interrupt Type 3
 The type 3 interrupt is produced by execution of the INT
3 instruction.
 The main use of the type 3 interrupt is to implement a
breakpoint function in a system.

Kassahun Tamir 11
Overflow Interrupt Type 4
 The 8086 overflow flag (OF) will be set if the signed
result of an arithmetic operation on two signed numbers
is too large to be represented in the destination register
or memory location.

Kassahun Tamir 12
HW Interrupt Applications
 One of the most common uses of Interrupts is to relieve
a CPU of the burden of polling.
 The disadvantage of polled input or output is that while
the microcomputer is polling the strobe or data ready
signal, it cannot easily be doing other tasks.
 So interrupt input and output is used to avoid this
problem.

Kassahun Tamir 13
Hardware Interrupt Application

Kassahun Tamir 14
Counting Application
 The interrupt-service procedure for that input can
simply increment a count stored in a named
memory location.

Kassahun Tamir 15
Bit Set-Reset Mode (BSR)
 In BSR mode only port C (PC0 - PC7) can be used to
set or reset its individual port bits.

 Any of the 8-bits of port C can be set or reset


depending on B0 of the control word.

 The bit to be set or reset is selected by bit select


flags B3, B2, and B1 of the CWR.

Kassahun Tamir 16
Bit Set-Reset Mode (BSR)

Kassahun Tamir 17
I/O - Mode
 Under the I/O mode of operation, further there are
three modes of operation of 8255 so as to support
different applications:-

Mode 0

Mode 1

Mode 2.

Kassahun Tamir 18
Mode 0 (Basic I/O Mode)
 This mode provides simple input and output
capability using each of the three ports.
 Data can simply be read from and written to the
input and output ports respectively, after
appropriate initialization.

Kassahun Tamir 19
Mode 0 (Basic I/O Mode)
 The salient features of this mode are:-

Two B-bit ports (port A and port B) and two 4-bit
ports (port C upper and lower) are available. The
two 4-bit ports can be combined and used as a
third 8-bit port.

Any port can be used as an input or output port.

Output ports are latched. Input ports are not
latched.
 All these modes can be selected by programming a
register internal to 8255, known as control word
register (CWR). Kassahun Tamir 20
Control Word Register Format

Kassahun Tamir 21
Example
 Interface an 8255 with 8086 to work as an I/O port.
Initialize port A as output port, port B as an input port,
and port C as output port. Port A address should be 07
40H.
 Write a program to sense switch positions SWO - SW7
connected at Port B. The sensed pattern is to be
displayed on port A, to which 8 LEDs are connected,
while the port C lower displays number of switches out
of the total eight switches.

Kassahun Tamir 22
Example

Kassahun Tamir 23
Example

Kassahun Tamir 24
Example
MOV DX, 0746H YY: ROL AL
MOV AL, 82H JNC XX
OUT DX, AL INC BL
SUB DX, 0004H XX: DEC CH
IN AL, DX JNZ YY
SUB DX, 0002H MOV AL, BL
OUT DX, AL ADD DX, 0004H
MOV BL, 00H OUT DX, AL
MOV CH, 08H HLT
Kassahun Tamir 25
Exercise
 Write a program to accept an input 8-bit data from
port number 125H and store the data to memory
address of 51000H.

 Solution:
MOV DX, 125H
IN AL, DX
MOV BX, 5000H
MOV DS, BX
MOV [1000H], AL Kassahun Tamir 26
Exercise
 Write a program to display an output 16-bit data to
port number 25H from a memory address of
51000H.

 Solution:
MOV AX, 5000H
MOV DS, AX
MOV AX, [1000H]
MOV DX, 25H
OUT DX, AX Kassahun Tamir 27
Questions?

Kassahun Tamir 28

You might also like