Home » Embedded System Interrupts in 8051 MicroController

Embedded System Interrupts in 8051 MicroController

by Online Tutorials Library

Interrupts in 8051 Microcontroller

It is a sub-routine calls that given by the microcontroller when some other program with high priority is request for acquiring the system buses than interrupt occur in current running program.

Interrupts provide a method to postpone or delay the current process, performs a sub-routine task and then restart the standard program again.


Types of interrupt in 8051 Microcontroller

Let’s see the five sources of interrupts in 8051 Microcontroller:

  • Timer 0 overflow interrupt – TF0
  • External hardware interrupt – INT0
  • Timer 1 overflow interrupt – TF1
  • External hardware interrupt – INT1
  • Serial communication interrupt – RI/TI

The timer and serial interrupts are internally produced by the microcontroller, whereas the external interrupts are produced by additional interfacing devices or switches that are externally connected with the microcontroller. These external interrupts can be level triggered or edge triggered.

When interrupt occur then the microcontroller executes the interrupt service routine. Therefore the memory location corresponds to interrupt enables it. Consider the interrupt corresponding to the memory location is shown in the interrupt vector table below.

Interrupts in 8051 Microcontroller1


Interrupt Structure of 8051 Microcontroller

After ‘RESET’ all the interrupts get disabled, and therefore, all the interrupts is enabled by software. From all the five interrupts, if anyone or all interrupt are activated, this will sets the corresponding interrupt flags as represent in the figure which corresponds to Interrupt structure of 8051 microcontroller:-

Interrupts in 8051 Microcontroller2

All the interrupts can be set or cleared by some special function register that is also known as interrupt enabled (IE), and it is totally depends on the priority, which is executed by using interrupt priority register.

Interrupt Enable (IE) Register

IE register is used for enabling and disabling the interrupt. This is a bit addressable register in which EA value must be set to one for enabling interrupts. The individual bits in this register enables the particular interrupt like timer, serial and external inputs. Consider in the below IE register, bit corresponds to 1 activate the interrupt and 0 disable the interrupt.

Interrupts in 8051 Microcontroller3

Interrupt Priority Register (IP)

Using IP register it is possible to change the priority levels of an interrupts by clearing or setting the individual bit in the Interrupt priority (IP) register as shown in figure. It allows the low priority interrupt can interrupt the high-priority interrupt, but it prohibits the interruption by using another low-priority interrupt. If the priorities of interrupt are not programmed, then microcontroller executes the instruction in a predefined manner and its order are INT0, TF0, INT1, TF1, and SI.

Interrupts in 8051 Microcontroller4


Interrupt programming in 8051

  1. Timer Interrupt Programming: In microcontroller Timer 1 and Timer 0 interrupts are generated by time register bits TF0 AND TF1. This timer interrupts programming by C code involves:
    • Selecting the configuration of TMOD register and their mode of operation.
    • Enables the IE registers and corresponding timer bits in it.
    • Choose and load the initial values of TLx and THx by using appropriate mode of operation.
    • Set the timer run bit for starting the timer.
    • Write the subroutine for a timer and clears the value of TRx at the end of the subroutine.

    Let’s see the timer interrupt programming using Timer0 model for blinking LED using interrupt method:

  2. External Hardware Interrupt Programming
  3. Microcontroller 8051 is consisting of two external hardware interrupts: INT0 and INT1 as discussed above. These interrupts are enabled at pin 3.2 and pin 3.3. It can be level triggered or edge triggered. In level triggering, low signal at pin 3.2 enables the interrupt, while at pin 3.2 high to low transition enables the edge triggered interrupt.

    Let us see the programmable feature of 8051 microcontroller are:

  • Enables the equivalent bit of external interrupt in Interrupt Enable (IE) register.
  • If it is level triggering, then write subroutine appropriate to this interrupt, or else enable the bit in TCON register corresponding to the edge triggered interrupt.

Consider the edge triggered external hardware interrupt programming is:-

  • Serial Communication Interrupt Programming It is used when there is a need to send or receive data. Since one interrupt bit is used for both Transfer Interrupt (TI) and Receiver Interrupt (RI) flags, Interrupt Service Routine (ISR) must examine these flags for knowing the actual interrupt. By the logical OR operation of RI and TI flags causes the interrupt and it is clear by the software alone. Consider the steps involved in serial communication interrupt programming are:-
    • Configure the Interrupt Enable register for enabling serial interrupt.
    • Configure the SCON register for performing transferring and receiving operation.
    • Write a subroutine for given interrupt with appropriate function.
  • Let’s see the program for sending ‘E’ through serial port with 9600 baud rate using Serial Interrupt:

    You may also like