View previous topic :: View next topic |
Author |
Message |
respected
Joined: 16 May 2006 Posts: 95
|
why doesnt stop RA or RB interrupt |
Posted: Fri Jun 27, 2014 12:47 pm |
|
|
Code: | #include <18F14K50.h>
#fuses INTRC_IO,NOMCLR,NOWDT,NOBROWNOUT,NOLVP
#use delay(internal=8000000)
#INT_RA
void RB_isr(void)
{
output_high(PIN_C3);
disable_interrupts(INT_RA5);
}
void main()
{
enable_interrupts(INT_RA5);
clear_interrupt(INT_RA5);
enable_interrupts(GLOBAL);
while(TRUE)
{
delay_ms(100);
output_low(PIN_C3);
}
} |
This is my code.
In fact interrupt works but it always works. when I make to change pin A5, Pin C3 is being high state but again when i make to change pin A5 , pin C3 doesn't change low state.
I use 4.024 vers. Thanks |
|
|
haxan7
Joined: 27 Jul 2013 Posts: 79
|
|
Posted: Fri Jun 27, 2014 1:19 pm |
|
|
You have to read the pin that caused the interrupt to reset the interrupt flag.
(call clear_interrupt(INT_RA5); at the end of ISR)
Otherwise program will reenter the ISR.
Also you are disabling the interrupts in the ISR, I don't think you mean to do that.
Remove this line
Code: | disable_interrupts(INT_RA5); |
Also try increasing the delay, delay is too low to be noticeable.
Last edited by haxan7 on Fri Jun 27, 2014 1:25 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19484
|
|
Posted: Fri Jun 27, 2014 1:21 pm |
|
|
With any interrupt, _you_ have to deal with the physical 'event' that triggers it.
So for the serial receive interrupt (for example), you have to read the received character, or the interrupt will keep triggering for ever (after all the character is still there wanting to be read...). For the 'interrupt on change' interrupts, you _must_ read the port that has changed in the handler. This resets the latch holding the 'copy' used to detect the change.
A search here will find dozens of posts explaining this. |
|
|
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Fri Jun 27, 2014 1:31 pm |
|
|
"you _must_ read the port that has changed in the handler"
you are right. how i forget it. Thanks
Code: | #include <18F14K50.h>
#fuses INTRC_IO,NOMCLR,NOWDT,NOBROWNOUT,NOLVP
#use delay(internal=8000000)
int a;
#INT_RA
void RB_isr(void)
{
a=input_state(pin_A5);
output_high(PIN_C3);
disable_interrupts(INT_RA5);
}
void main()
{
enable_interrupts(INT_RA5);
clear_interrupt(INT_RA5);
enable_interrupts(GLOBAL);
while(TRUE)
{
delay_ms(5000);
output_low(PIN_C3);
enable_interrupts(INT_RA5);
}
} |
|
|
|
|