CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

why doesnt stop RA or RB interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

why doesnt stop RA or RB interrupt
PostPosted: Fri Jun 27, 2014 12:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 1:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 1:21 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 1:31 pm     Reply with quote

"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);                               
   }         

}     
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group