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

Double interrupt doesnt work

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

Double interrupt doesnt work
PostPosted: Wed Dec 11, 2013 3:37 am     Reply with quote

Hello Guys! I am trying to create a code that should respond on two pin interrupt H2L edge.The first interrupt is INT_RB7_H2L and second one is INT_RA5_H2L. The problem is that only one works, depends on which one has bigger priority. I simplified the code for easily understanding the issue.
Here is the code:
Code:

#include <16F1508.h>
#fuses NOWDT,NOMCLR,INTRC_IO
#use delay(clock=16M)

#define valves pin_c5
#PRIORITY INT_RA,INT_RB

#INT_RA
   void dec_button()
      {
         if (!input(pin_A5))
            {
               output_high(valves);
            }
      clear_interrupt(INT_RA5_H2L);
      }

#INT_RB
   void inc_button()
      { 
         if(!input(pin_b7))
            {
               output_low(valves);
            }
      clear_interrupt(INT_RB7_H2L);
      }

void main()
{
   ENABLE_INTERRUPTS(INT_RA5_H2L);
   ENABLE_INTERRUPTS(INT_RB7_H2L);
   ENABLE_INTERRUPTS(GLOBAL);

   while(true)
      ;
}

Sorry for bad English!
Thanks in advance! Very Happy
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Wed Dec 11, 2013 9:38 am     Reply with quote

The compiler clears the physical interrupt for you - so get rid of the line doing this.
However what it doesn't do is clear the IOCB flags. These are a set of flags to say 'which pin' triggered the interrupt.

Add this:
Code:

#byte IOCAF = 0x393
#byte IOCBP = 0x394
#define clear_IOCA_flags() IOCAF = 0
#define clear_IOCB_flags() IOCBF = 0


and call these functions (IOCA for INT_RA, and IOCB for INT_RB), instead of the clear_interrupt line.

So:
Code:

#INT_RA
void dec_button(void)
{
     if (!input(pin_A5))
     {
          output_high(valves);
     }
     clear_IOCA_flags();
}


Best Wishes
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