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

Interrupt to occur on bits B6 and B7 only

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



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

Interrupt to occur on bits B6 and B7 only
PostPosted: Thu Jul 16, 2009 2:43 pm     Reply with quote

Hi All,

I would like to use the Interrupt on change in PORT B. I understand this works on the top 4 bits of port B. However I need the interrupt to occur on bits B6 and B7 only. B4 and B5 are used already and I need to ignore them. Is there some way to mask out the unwanted pins or only interrupt on Bits 6 & 7?

I am using a PIC 18F2520 and I have 4.073.

Thanks, Ray
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 16, 2009 5:14 pm     Reply with quote

The 18F2520 doesn't have a mask register for the interrupt-on-change
pins. But the 18F25K20 (i.e., K-series) does have it. The IOCB register
in that PIC can be used to enable only specific pins in B4-B7 for interrupts.
frierray



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

PostPosted: Thu Jul 16, 2009 6:23 pm     Reply with quote

PCM Programmer,

Thanks for the input, I'll have a look at the K20 next. However I'll need to run this on a 2520 as it is installed on the board at this time. I have used the interrupt-on-change before but with a key pad, so all 4 pins were used to detect a key pressed and it worked great. I think in this case I'll just take all the interrupts on the port and service only the ones on B6 and B7.

Thanks Ray
Guest








PostPosted: Fri Jul 17, 2009 3:23 am     Reply with quote

Basically, you have to 'service' them all, but return immediately, on the ones you don't want. So your ISR, needs something like:
Code:

static int8 old; //In your 'main', initialise this to match portB, before
//enabling the interrupt - old=input_b();

#INT_RB
void Bchanged(void) {
   int8 changed;
   int8 portval;
   portval=input_b();
   changed=(portval ^ old) & 0xA0;
   //if 'changed' is now non zero, B6, or B7 has changed
   if (changed) {
       //Here you have the 'current' value of portB, in 'portval'
       //and flags reflecting which bit has changed in 'changed'.
       //test these as needed to find what bit has changed
       if (bit_test(changed,6)) {
          //Here B6 has changed
          if (bit_test(portval,6)) {
             //Here B6 has gone high
          }
          else {
             //Here B6 has gone low
          }
       }
       //Test only for the combination you need (high/low), and repeat
       //for B7.

  }
  old=portval;
  //You will exit if the 'change' was not B6 or B7
}

It looks bulky, but is actually very quick (the tests are basically all just two instruction cycles).

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