Enable Interrupt inside another interrupt

Status
Not open for further replies.

cool.man

Full Member level 6
Joined
May 29, 2008
Messages
323
Helped
42
Reputation
84
Reaction score
29
Trophy points
1,308
Location
Earth
Activity points
3,307
Hi,
I am using PIC18f252 and CCS compiler.
What i want to do is that whenever Interrupt comes at PIN_B1,it enables the interrupt on PIN_B0 and when no interrupt on PIN_B1,the interrupt on PIN_B0 disable's.

My theme is that i have a switch on a PIN_B1 and pulses coming from outside are at PIN_B0.when Switch is "ON" interrupt generate on PIN_B1 which enables the interrupt on PIN_B0 and pulses read by the microcontroller.
When the switch is at "OFF" position,interrupt at PIN_B1 and PIN_B0 should be disable.
Can anyone give me a basic idea how to do that.
 

This is a pseudo code.
Enable interrupt at switch input
In its ISR:
Code:
If switch on
Enable second interrupt
Do whatever processing
Else
Disable second Interrupt
Do whatever processing
End If
Return from interrupt
 

I have made a code but sometimes it works and sometime not (interrupt0 sometimes activated and sometimes not).
What i have done in this is that whenever switch is pressed, In the routine of #INT_EXT1 interrupt EXT will be enabled.when interrupt EXT enabled it toggle the PIN_C2 according to the pulses .
I am checking the position of the switch in the while loop,whenever the switch is OFF it will disable the interrupt0.
What changes are required?
This is the sample program for my understanding.
Code:
short a=0;

#INT_EXT
void EXT_isr(void)
{
 if(a==1)//check if interrupt0 is enabled
 {
  output_toggle(PIN_C2);//toggle an led according to the pulses
 } 
}

#INT_EXT1
void EXT1_isr(void)
{
 a=1;
 if(a==1)
 {
  output_toggle(PIN_C1);//toggle an led whenever switch is ON
  ext_int_edge(0,L_TO_H);//interrupt0 generate at low to high transaction
  enable_interrupts(INT_EXT);
 }
}

void main()
{
 ext_int_edge(1,H_TO_L);//interrupt1 generate at high to low transaction
 enable_interrupts(INT_EXT1);//interrupt1 is enable here
 enable_interrupts(GLOBAL);
 
 while(1)
 {
  if(input(PIN_B1))//check if switch is OFF
  {
   a=0;//
   disable_interrupts(INT_EXT);//disable interrupt0
  }
  output_toggle(PIN_C0);//toggle an LED continuously
  delay_ms(500);
 }
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…