interrupt programming
interrupt programming
The Microcontroller can serve several devices. The Interrupt is the method to
indicate the microcontroller by sending an interrupt signal. After receiving an interrupt,
the microcontroller interrupts whatever it is doing and serves the device. The program
associated with the interrupt is called the interrupt service routine (ISR). When an
interrupt is invoked, the microcontroller runs the interrupt service routine. For every
interrupt, there is a fixed location set aside to hold the addresses of ISRs.
[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay, pg.no.320]
Upon reset all interrupts are disable, meaning that known will be responded to by
the microcontroller if they are activated. The Interrupt must be enabled by software in
order for microcontroller to respond to them there is a register called IE that is responsible
for enabling and disabling the interrupts as shown in Figure 5.3.1
execution of current instruction whatever it is executing and jumps to the vector table to
perform the interrupt service routine.
TYPES OF INTERRUPT
1)Level-TriggeredInterrupt
2)Edge -Triggered Interrupt
LEVEL-TRIGGERED INTERRUPT
In this mode, INT0 and INT1 are normally high and if the low level signal is
applied to them, it triggers the Interrupt. Then the microcontroller stops and jumps to the
interrupt vector table to service that interrupt. The low-level signal at the INT pin must
be removed before the execution of the last instruction of the ISR, RETI. Otherwise,
another interrupt will be generated. This is called a level-triggered or level-activated
interruptandis the default mode upon reset
[Source: “The 8051Microcontroller and Embedded Systems: Using Assembly and C” by Mohamed Ali Mazidi,
Janice Gillispie Mazidi, Rolin McKinlay, pg.no.327]
TI (transfer interrupt) is raised when the stop bit is transferred indicating that the SBUF
register is ready to transfer the next byte
RI (received interrupt) is raised when the stop bit is received indicating that the received
byte needs to be picked up before it is lost (overrun) by new incoming serial data
In the 8051 there is only one interrupt set aside for serial communication ,used for both
sending and receiving data.
If the interrupt bit in the IE register (IE.4) is enabled, when RI or TI is raised the 8051
gets interrupted and jumps to memory location 0023H to execute the ISR
In that ISR we must examine the TI and RI flags to see which one caused the interrupt
and respond accordingly.
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.