INT0 and INT1 interrupt in 8051
SIMULATOR: PROTEUS 8.0
SOFTWARE: KEIL
4.0
CIRCUIT DIAGRAM:
WORKING:
Any event which occurred internally or externally in a microcontroller that stops the current execution of the program is called an interrupt. Whenever an interrupt occurs, the microcontroller stops the current execution of the program and executes the program written for the interrupt which is also called the ISR (interrupt service routine).
Here in this project, I have used int0 and int1 interrupt. To enable the interrupt operation respective bit in the IE register must be equal to 1. I have connected sw1 to INT0 pin of 8051 and sw2 to INT1 pin of 8051.
If sw1 is pressed, it provides an active low signal to INT0 pin of 8051 which activates the INT0 interrupt. If sw2 is pressed, it provides an active low signal to INT1 pin of 8051 which activates the INT1 interrupt. Here in the ISR of INT0, I have written the logic to turn ON the LEDs and in the ISR of INT1, I have written the logic to blink the LEDs.
Therefore, whenever sw1 is pressed LEDs get turned on and whenever sw2 is pressed LEDs start blinking.
PROGRAM:
#include<reg51.h>
void delay(unsigned int t); // delay function
sbit LED1=P2^0; // blue
sbit LED2=P2^2; // green
void ISR1(void) interrupt 0 // interrupt isr for int0
{
LED1= 0;// turn on led 1 (blue)
LED2= 0;// turn on led 2(green)
delay(5);
}
void ISR2(void) interrupt 2 // interrupt isr for int1
{
LED1= ~LED1; // blink led 1 (blue)
LED2= ~LED2; //
blink led 2 (green)
delay(5);
}
int main() // main program
{
LED1=1; // turn off the led 1
LED2=1; // turn
off the led 2
EA=1; //Enabling the interrupt register
EX0=1; // Enabling the external interrupt 0
EX1=1; // Enabling the external interrupt 1
while(1)
{
LED1=1; // LED 1 forever off
LED2=1; // LED 2 forever off
}
}
void delay(unsigned int t)
{
unsigned int i;
for(i=0;i<=1234*t;i++);
}
PROGRAM DESCRIPTION:
IE REGISTER:
EA |
- |
ET2 |
ES |
ET1 |
EX1 |
ET0 |
EX0 |
D7 |
D6 |
D5 |
D4 |
D3 |
D2 |
D1 |
D0 |
EA = 1 ; All the interrupts are enabled.
EA = 0 ; All the interrupts are disabled.
To activate any interrupt EA bit should be equal to 1 along with its respective bit in the IE register.
For example, If we want to activate int0 interrupt then first we need to make EA bit equal to 1 and after that EX0 bit equal to 1. Without this, we can not able to activate int0 interrupt. If we make EX0 equal to 1 then also we can not able to activate int0 interrupt until we make EA bit equal to 1.EA is like a switch to enable interrupt operation in 8051.
EX1 = 1 ; External interrupt INT1(bar) is enabled
EX1 = 0 ; External interrupt INT1(bar) is disabled
EX0 = 1 ; External interrupt INT0(bar) is enabled
EX0 = 0 ; External interrupt INT0(bar) is disabled
INT0 and INT1 are active low interrupt. If these interrupts are enabled (respective bits are set in IE register) and if any active low signal gets applied to pin int0 and pin int1 of 8051 then it will activate both the interrupts.
Whenever INT0 interrupt gets activated, the program counter stops its current execution and vectored to location 0003h(ISR location for INT0 interrupt) and performs the task written in the ISR.
Whenever INT1 interrupt gets activated, the program counter stops its current execution and vectored to location 0013h(ISR location for INT1 interrupt) and performs the task written in the ISR.
Declaration of ISR function in C:
Here ISR Name can be any name. Interrupt number for INT0 is 0 and Interrupt number for INT1 is 2.
Comments
Post a Comment