How to end external Interrupt Service Routine (ISR) in 8051

762 views Asked by At

I wrote a simple led blinking code with hardware interrupt 0 of 8051. When button is pressed it goes into interrupt service routine (ISR). After executing it should come back in main function but it is not coming. This is my c code. Any positive reply will be appreciated.

sbit LED = P1^0;

void delay(int ms)
{ 
   int i;

   for(i=0;i<ms;i++)
   {
     TMOD = 0x01;             
     TH0 = 0xFC;             
     TL0 = 0x66;
     TR0 = 1; 
     while(TF0==0);                                     
     TR0 = 0;
     TF0 = 0;
   }
}



void main(void)
{
    P1 = 0x00;
/// P3 = 0x04;
    IT0 = 1;     
    EX0 = 1;      
    EA  = 1; 
    LED=1;

    while(1)
    {   
      LED=~LED;
      delay(200);
    }

 return ;
}



void external0_isr() interrupt 0     
{ 
   EA=0;
   LED =0 ;
   delay(2000);
   LED=1;
   EX0=1;
   EA=1;

   return;
} 
1

There are 1 answers

7
Ngo Thanh Nhan On BEST ANSWER

When you enter the button interrupt, you disable global interrupt EA=0; That also disables the timer interrupt. Therefore, you program would hang at while(TF0==0) in your delay(2000) routine.