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

A Brief Overview

Types of Interrupts in 8051


INT0

All 8051 interrupts except RST


 Hardware are Maskable Interrupts
INT1

Serial Port Interrupt (P1 or R1)

 Software
Timer1 Flag Interrupt TF1

Timer0 Flag Interrupt TF0


8051 - Pin Diagram

Serial Interrupt

Hardware

Timer Interrupts

Image from: Kenneth J. Ayala, The 8051 Microcontroller


Types of Interrupts in 8051 (cntd.,)
 Special kind of Interrupt – RESET

 RESET – active high signal

 On RESET, PC is cleared and program starts execution


from 0000h of the code memory

 All SFRs restored to POR (Power On Reset) values

 RESET - Non-maskable interrupt


Registers Associated with
Interrupt’s functions

Interrupt Enable (IE)


Interrupt Priority (IP)
TCON register
Interrupt Control
 8051 Interrupts can be enabled or disabled by altering
the content of IE register

 Each Interrupt can be controlled individually by


setting or resetting appropriate bits in IE register
(‘1’ for enabling and ‘0’ for disabling)

 Priorities can be set to interrupts by altering the


contents of IP register
Interrupt Enable (IE) Register
IE register - Example
1 X X 0 0 1 0 1

Global Interrupt Enable Enable Hardware Interrupt


INT0 and INT1
Interrupt Priority
 Bits of IP register decides which of the five
interrupts to have High Priority
 When two interrupts have same priority, the
following ranking is assigned:
1. INT0 Highest Priority
2. TF0 (Timer 0)
3. INT1
4. TF1 (Timer 1)
5. Serial (R1 or T1) Lowest Priority
Interrupt Priority (IP) Register
IP register - Example

X X X 1 0 0 0 0

Priority to Serial
Interrupt
IP register - Example

X X X 0 0 1 0 1

Priority to INT0 and INT1

Note:
INT0 and INT1 has same priority. So, 8051 follows the default ranking
Which means INT0 has more priority than INT1
Interrupt Destination
 When an INTERRUPT occurs, the program execution
point is transferred to the Interrupt Destination of that
particular interrupt
Interrupt Destination (cntd.,)
 The Programmer has to make sure that the ISR of a
particular interrupt is present in the destination
address
 A RETI instruction is used to return from the ISR.
 Simultaneously, the RETI instruction resets interrupt
logic so that another interrupt can be serviced
TCON Register

Note:
Generating Interrupts by Software
 When an Interrupt Flag is set to ‘1’ by any means, an
interrupt is generated unless blocked
Interrupt functions in 8051 C
void <interrrupt_name> (void) interrupt
<interrupt_number> using <register bank no.>

The using function attribute is used to select a register bank different from that of the
non-interrupt program code
The following rules apply to interrupt
functions:
 No function arguments may be specified for an
interrupt function
 The compiler generates an interrupt vector for each
interrupt function automatically
 The Cx51 Compiler allows interrupt numbers within
the 0-31 range
 ‘Functions’ called from an ‘interrupt procedure’ must
function with the same register bank as the interrupt
procedure
Example
void falarm (void) interrupt 1 using 3
{
alarm_count = count + 2;
alarm = 1;
}
Fin
IE

IP

TCON

You might also like