8085 Interrupts
8085 Interrupts
8085 Interrupts
• Interrupt is a process where an external device can get the attention of the microprocessor.
• The process starts from the I/O device
• The process is asynchronous
Interrupts •
•
An interrupt is a hardware-initiated subroutine CALL.
Main routine
Interrupt
Go to
service
Go back
routine
Get
original RET
program
counter Service routine
Interrupt processing flow
Main program
Interrupt N
Req
Accept N
Interrupt
Get interrupt
vector
Jump to ISR
Save PC
Load PC
Responding to
Interrupts
• Responding to an interrupt may be immediate or
delayed depending on whether the interrupt is
maskable or non-maskable and whether interrupts
are being masked or not.
• There are two ways of redirecting the execution to
the ISR depending on whether the interrupt is
vectored or non-vectored.
• Vectored: The address of the subroutine is
already known to the Microprocessor
• Non Vectored: The device will have to supply
the address of the subroutine to the
Microprocessor
The Purpose of Interrupts
• Interrupts are useful when
interfacing I/O devices with low
data-transfer rates, like a keyboard
or a mouse, in which case polling
the device wastes valuable
processing time
• The peripheral interrupts the normal
application execution, requesting to
send or receive data. Main Program
Printer Interrupt
Main Program
Modem Interrupt
Main Program
Modem Interrupt
Main Program
In systems with more than one interrupt inputs, some interrupts have a higher priority than other
Interrupt priority:
•They are serviced first if multiple interrupts are triggered simultaneously
Interrupt vector: Code loaded on the bus by the interrupting device that contains the Address (segment and offset) of specific interrupt service routine
• A software interrupt is a particular instructions that can be inserted into the desired location in the program. There are eight
Software interrupts in 8085 Microprocessor. From RST0 to RST7.
• RST0, RST1, RST2, RST3, RST4, RST5, RST6, RST7
• They allow the microprocessor to transfer program control from the main program to the subroutine program. After completing
the subroutine program, the program control returns back to the main program.
• We can calculate the vector address of these interrupts using the formula given below:
Vector Address = Interrupt Number * 8
• So we can find simply vector address. For Example:
• RST2: vector address=2*8 = 16
• RST5: vector address=5*8 = 40
Software Interrupts in the 8085 – RST
Instructions
Binary Codes
Mnemonics HEX Address
D7 D6 D5 D4 D3 D2 D1 D0
RST0 1 1 0 0 0 1 1 1 C7 0000
RST1 1 1 0 0 1 1 1 1 CF 0008
RST2 1 1 0 1 0 1 1 1 D7 0010
RST3 1 1 0 1 1 1 1 1 DF 0018
RST4 1 1 1 0 0 1 1 1 E7 0020
RST5 1 1 1 0 1 1 1 1 EF 0028
RST6 1 1 1 1 0 1 1 1 F7 0030
RST7 1 1 1 1 1 1 1 1 FF 0038
• The restart sequence is made up of three machine
cycles
• In the 1st machine cycle:
• The microprocessor sends the INTA signal.
• While INTA is active the microprocessor
reads the data lines expecting to receive,
The 8085 from the interrupting device, the opcode for
the specific RST instruction.
Software • In the 2nd and 3rd machine cycles:
• the 16-bit address of the next instruction is
Interrupt Process - saved on the stack.
• Then the microprocessor jumps to the
Restart Sequence address associated with the specified RST
instruction.
• See the Page 96, Figure 3.17, of your Text Book for the
Timing Diagram of the RST instruction
Hardware Generation of RST Opcode
• How does the external device produce the opcode for the appropriate
RST instruction?
• The opcode is simply a collection of bits.
• So, the device needs to set the bits of the data bus to the appropriate value in
response to an INTA signal.
+5v
1
1
bus
EF to data
1
0
1
1
1
1
Enabling RST5
• During the interrupt acknowledge
machine cycle, (the 1st machine cycle
of the RST operation):
• The Microprocessor activates the
INTA signal.
Hardware • This signal will enable the Tri-state
buffers, which will place the value
Generation of EFH on the data bus.
• Therefore, sending the
RST Opcode Microprocessor the RST 5
instruction.
• INTR
Maskable • RST Vectored
Non-
• TRAP
Maskable
• RST5.5, RST6.5,
Vectored RST7.5, TRAP
Hardware Interrupts in the 8085
TRAP
RST7.5
RST6.5
RST 5.5 8085
INTR
INTA
Hardware
Interrupts in
the 8085
• An interrupt vector is a pointer
the memory location of an interrupt
handler, which prioritizes
interrupts and saves them in a queue
Interrupt • All interrupts (vectored) are mapped
onto a memory area called the
Vectors and Interrupt Vector Table (IVT).
• The IVT is usually located in
the Vector memory page 00 (0000H - 00FFH).
Table • The purpose of the IVT is to hold
the vectors that redirect the
microprocessor to the right place
when an interrupt arrives.
The 8085 Non-Vectored Interrupt Process
(INTR)
1. The interrupt process should be enabled using the EI instruction.
2. The 8085 checks for an interrupt during the execution of every instruction.
3. If INTR is high, MP completes current instruction, disables the interrupt flip-flop and sends INTA
(Interrupt acknowledge) signal to the device that interrupted
4. INTA allows the I/O device to send a RST instruction through data bus.
5. Upon receiving the INTA signal, MP saves the memory location of the next instruction on the
stack and the program is transferred to ‘call’ location (ISR Call) specified by the RST instruction
6. Microprocessor Performs the ISR.
7. ISR must include the ‘EI’ instruction to enable the further interrupt within the program.
8. RET instruction at the end of the ISR allows the MP to retrieve the return address from the
stack and the program is transferred back to where the program was interrupted.
The 8085A processor executes a number of machine
cycles, in response to a non-vectored interrupt
(INTR), prior to execution of the first instruction of
the interrupt service routine.
Machine
Cycles with The processor completes the execution of the current
instruction. (Note : The processor only samples the
Non-Vectored interrupt inputs in the last T-state of the last machine
cycle in the current instruction cycle)
Interrupts
(INTR) This has implication in system design as it means that
the interrupt signal on INTR must remain in the
asserted state for at least the longest instruction in
the 8085A instruction set to guarantee that the
processor recognises the interrupt.
The processor then executes a six T-state interrupt acknowledge
machine cycle ( the INTA machine cycle is similar to the opcode fetch
machine cycle except that the program counter is not incremented
and the INTA* control signal is asserted instead of RD*)
Machine In response to the INTA* signal, the interrupting device need to place
the opcode of an instruction onto the data bus ( called jamming ).
Cycles with
Non-Vectored The processor reads the opcode in the normal manner and stores it in
the instruction register.
Interrupts
(INTR) The choice of opcode is restricted as it is necessary to automatically
save the contents of the program counter to enable the program to
return to the point in the software where it was interrupted.
The only viable choice of 8085A instruction is either the CALL
instruction or the RST n instruction.
Machine The processor firstly executes two memory write machine cycles
to save the current contents of the program counter onto the
33
Machine Cycles with Non-Vectored Interrupts (INTR)
The execution phase of the CALL instruction can now take place.
The processor firstly executes two memory write machine cycles to
save the current contents of the program counter onto the stack. The
address as to where in memory the contents of PC is to be saved is
specified by the stack pointer register. 36
Machine Cycles with Non-Vectored Interrupts (INTR)
• The solution is to use a circuit called the priority encoder (74LS148 / 74LS138).
• This circuit has 8 inputs and 3 outputs.
• The inputs are assigned increasing priorities according to the increasing index of the
input.
• Input 7 has highest priority and input 0 has the lowest.
• The 3 outputs carry the index of the highest priority active input.
The 8085 Non-Vectored Interrupt Process
(INTR) - Multiple Interrupts & Priorities
• Note that the opcodes for the different RST instructions follow a set pattern.
• Bit D5, D4 and D3 of the opcodes change in a binary sequence from RST 7 down to RST 0.
• The other bits are always 1.
• This allows the code generated by the 74366 to be used directly to choose the appropriate RST
instruction.
• The one draw back to this scheme is that the only way to change the priority of the devices connected to
the 74366 is to reconnect the hardware.
The 8085 Non-
Vectored
Interrupt
Process (INTR) -
The Priority
Encoder
The 8085 Maskable/Vectored Interrupts
• The 8085 has 3 Masked/Vectored
interrupt inputs.
• RST 5.5, RST 6.5, RST 7.5
• They are all maskable.
• They are automatically
vectored according to
the following table:
• The vectors for these
interrupt fall in between
the vectors for the RST
instructions. That’s why
they have names like RST
5.5 (RST 5 and a half).
Masking RST 5.5, RST 6.5 and RST 7.5
M 7.5
RST 6.5
M 6.5
RST 5.5
M 5.5
INTR
Interrupt
Enable
Flip Flop
The 8085 Vectored Maskable Interrupt
Process (RST)
1. The interrupt process should be enabled using the EI instruction.
2. The 8085 checks for an interrupt during the execution of every instruction.
3. If there is an interrupt, and if the interrupt is enabled using the interrupt mask, the microprocessor
will complete the executing instruction, and reset the interrupt flip flop.
4. The microprocessor then executes a call instruction that sends the execution to the appropriate
location in the interrupt vector table.
5. When the microprocessor executes the call instruction, it saves the address of the next instruction
on the stack.
6. The microprocessor jumps to the specific service routine.
7. The service routine must include the instruction EI to re-enable the interrupt process.
8. At the end of the service routine, the RET instruction returns the execution to where the program
was interrupted.
Since there is no requirement to supply ISR addresses with direct
interrupts ( TRAP, RST 5.5, RST 6.5 & RST 7.5 ) then there is no
requirement for the 8085A to execute INTA machine cycles in
response to such interrupts.
However to provide the CPU sufficient time to process direct interrupt
Machine - six T-state bus idle machine cycle is introduced, following
recognition of the direct interrupt.
Cycles with During the bus idle machine cycle, no control signal is asserted nor is
the program counter incremented. Ready line control is ignored
Direct during the bus idle cycle.
Interrupts Following with the bus idle cycle which is two memory write cycles
are executed to save the current contents of the program counter on
(Vectored) the stack.
49
Machine Cycles with Direct Interrupts (Vectored)
M6.5
SDO
M5.5
M7.5
SDE
MSE
XXX
R7.5
Serial Data Out RST5.5 Mask
RST7.5 }
RST6.5 Mask 0 - Available
1 - Masked
Mask
Mask Set Enable
Enable Serial Data
0 - Ignore bits 0-2
0 - Ignore bit 7
1 - Set the masks according
1 - Send bit 7 to SOD pin
to bits 0-2
Bits 4 and 5 return the current value of the RST5.5 and RST6.5
Bits 4-6 show whether or not there are pending pins.
interrupts on RST 7.5, RST 6.5, and RST 5.5 Bit 6 returns the current value of the RST7.5 memory flip flop.
The RIM instruction reads the value of the SID pin on the
Bit 7 is used for Serial Data Input. microprocessor and returns it in this bit.
• Since the 8085 has five interrupt lines,
interrupts may occur during an ISR and remain
Pending pending.
• Using the RIM instruction, it is possible to
Interrupts can read the status of the interrupt lines
and find if there are any pending interrupts.
• TRAP is the only non-maskable interrupt.
• It does not need to be enabled
because it cannot be disabled.
• It has the highest priority amongst
interrupts.
• It is edge and level sensitive.
• It needs to be high and stay high to be
TRAP recognized.
• Once it is recognized, it won’t be
recognized again until it goes low, then
high again.
Main program
Service routine
LXI SP, XX99H XX70: SERV: PUSH B
EI PUSH PSW
MVI A, 00H MVI B, 0AH
MVI A, 00H
NXTCNT: OUT PORT1
FLASH: OUT PORT1
MVI C, 01H MVI C, 01H
CALL DELAY CALL DELAY
INR A CMA
JMP NXTCNT DCR B
JNZ FLASH
POP PSW
POP B
Interrupt instr: EF EI
At 0028H JMP xx70H RET
Using SIM instruction to Modify the Interrupt Mask
Example 1 : Set the interrupt masks so that RST 7.5 and RST 5.5
is enable and disable RST6.5
M7.5
M6.5
M5.5
SDO
MSE
R7.5
SDE
XXX
Enable RST 7.5 bit 2 = 0
Allow setting the masks bit 3 = 1
Don’t reset the flip flop bit 4 = 0 0 0 0 0 1 0 1 0
Bit 5 is not used bit 5 = 0
Don’t use serial data bit 6 = 0 Contents of accumulator are: 0AH
Serial data is ignored bit 7 = 0
MVI A, 0A H
SIM ;Set Interrupt Mask
EI ;Enable Interrupt
Using SIM instruction to Modify the Interrupt Mask
Example 2 : Reset RST 7.5 interrupt from example 1
M7.5
M6.5
M5.5
SDO
MSE
R7.5
SDE
XXX
Enable RST 7.5 bit 2 = 0
Allow setting the masks bit 3 = 1
Reset the flip flop bit 4 = 1 0 0 0 1 1 0 1 0
Bit 5 is not used bit 5 = 0
Don’t used serial data bit 6 = 0 Contents of accumulator are: 1AH
Serial data is ignored bit 7 = 0
MVI A, 1A H
SIM ;Set Interrupt Mask
EI ;Enable Interrupt