8051 INTERRUPT



Interrupts:

The interrupts refer to a notification, communicated to the controller, by a hardware device or software, on receipt of which controller momentarily stops and responds to the interrupt. Whenever an interrupt occurs the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine (ISR) or Interrupt Handler. ISR is a piece of code that tells the processor or controller what to do when the interrupt occurs. After the execution of ISR, controller returns back to the instruction it has jumped from (before the interrupt was received). The interrupts can be either hardware interrupts or software interrupts. 





Interrupt Sources:    

      Original 8051 has 6 sources of interrupts
·       Reset
·       Timer 0 overflow
·       Timer 1 overflow
·       External Interrupt 0
·       External Interrupt 1
·       Serial Port events buffer full, buffer empty, etc)

External interrupt Example: (INT0):


        include<reg51.h>

sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^3;
void command();
   void display();
unsigned int arr1[5]={0x38,0x06,0x01,0x0e,0x80};
unsigned char arr2[10]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f};
unsigned char arr3[14]={"WELCOME TO ALL"};
int a,b,c;
int i,j;
void de(unsigned int n);
void ISR()interrupt 0
{
for(a=0;a<=9;a++)
{
P2=arr2[a];
de(100);
}
}
void main()
{

IE=0x81;
while(1)
{
for(b=0;b<=4;b++)
{
P1=arr1[b];
command();
}

for(c=0;c<=13;c++)
{
P1=arr3[c];
display();
}
}

}
void de(unsigned int n)
{
for(i=0;i<=n;i++)
{
for(j=0;j<=1000;j++);
}
}

void command()
{
rs=0;
rw=0;
en=1;
de(100);
en=0;
}
void display()
{
rs=1;
rw=0;
en=1;
de(100);
en=0;
}


#

Comments

Popular posts from this blog

Serial Communication With 8051 Microcontroller