Professional Documents
Culture Documents
Interrupts provide a method to postpone or delay the current process, performs a sub-
routine task and then restart the standard program again.
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.
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:-
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.
Let's see the timer interrupt programming using Timer0 model for blinking LED
using interrupt method:
1. #include< reg51 .h>
2. sbit Blink Led = P2^0; // LED is connected to port 2 Zeroth pin
3. void timer0_ISR (void) interrupt 1 //interrupt no. 1 for Timer0
4. {
5. Blink Led=~Blink Led; // Blink LED on interrupt
6. TH0=0xFC; // loading initial values to timer
7. TL0=0x66;
8. }
9. void main()
10. {
11. TMOD=0x0l; // mode 1 of Timer0
12. TH0 = 0xFC: // initial value is loaded to timer
13. TL0 = 0x66:
14. ET0 =1; // enable timer 0 interrupt
15. TR0 = 1; // start timer
16. while (1); // do nothing
17. }
1. void main()
2. {
3. IT0 = 1; // Configure interrupt 0 for falling edge on INT0
4. EXO = 1; // Enabling the EX0 interrupt
5. EA =1; // Enabling the global interrupt flag
6. }
7. void ISR_ex0(void) interrupt 0
8. {
9. <body of interrupt>
10. }
Let's see the program for sending 'E' through serial port with 9600 baud rate
using Serial Interrupt:
1. void main()
2. {
3. TMOD = 0x20:
4. TH1= 0xFD; // baud rate for 9600 bps
5. SCON = 0x50;
6. TR1=1;
7. EA=l;
8. whlle(l);
9. }
10. void ISR_Serial(void) interrupt 4
11. {
12. if(TI==l)
13. {
14. SBUF= ?E?;
15. TI=0;
16. }
17. else
18. RI =0;
19. }