14-Programming of Hardware Interrupts - Int0 & Int1-06-03-2023
14-Programming of Hardware Interrupts - Int0 & Int1-06-03-2023
14-Programming of Hardware Interrupts - Int0 & Int1-06-03-2023
• Interrupts are basically the events that temporarily suspend the main program, pass
the control to the external sources and execute their task. It then passes the control
to the main program where it had left off.
• 8051 has five interrupts.
• These interrupts are
INT0
INT1
T0
T1
TI/RI
• All of the interrupts can be enabled or disabled by using the IE (interrupt enable)
register.
The interrupt addresses of these interrupts are like below −
Interrupt Enable (IE)Register:
This register can be used to enable or disable interrupts programmatically.
This register is an SFR.
The address is A8H.
This byte is bit addressable.
So it can be programmed by the user.
The bits in this register has a different meaning.
Now, let us see the bit details and different operations when the value is low (0) and
high(1).
Example: Show the instructions to (a) enable the serial interrupt, Timer 0 interrupt,
and external hardware interrupt 1 (EX1), and (b) disable (mask) the Timer 0 interrupt,
then (c) show how to disable all the interrupts with a single instruction.
Solution:
(a)MOV IE,#10010110B ;enable serial, Timer 0, EX1
Since IE is a bit-addressable register, we can use the following instructions to access
individual bits of the register.
(b)CLR IE.1 ;mask(disable) Timer 0 interrupt only
(c)CLR IE.7 ;disable all interrupts
Another way to perform the “MOV IE,#10010110B” instruction is by using single-bit
instructions as shown below.
SETB IE.7 ;EA=1, Global enable
SETB IE.4 ;enable serial interrupt
SETB IE.1 ;enable Timer 0 interrupt
SETB IE.2 ;enable EX1
Interrupt Priority (IP) Register:
All of these five interrupts can be in one or two interrupt level.
The priority levels are level 1 and level 0.
Priority level 1 indicates the higher priority, and level 0 indicates lower priority.
This IP register can be used to store the priority levels for each interrupt.
This is also a bit addressable SFR.
Its address is B8H.
Now, let us see the bit details and different operations when the value is low (0) and
high(1).
Programming Timer Interrupts
• The timer flag (TF) is raised when the timer rolls over. In polling TF, we
have to wait until the TF is raised. The microcontroller is tied down
while waiting for TF to be raised, and cannot do anything else. If the
timer interrupt in the IE register is enabled, whenever the timer rolls
over, TF is raised. This avoids tying down the controller.