View previous topic :: View next topic |
Author |
Message |
frierray
Joined: 11 Nov 2008 Posts: 29
|
Interrupt to occur on bits B6 and B7 only |
Posted: Thu Jul 16, 2009 2:43 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 16, 2009 5:14 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
frierray
Joined: 11 Nov 2008 Posts: 29
|
|
Posted: Thu Jul 16, 2009 6:23 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Fri Jul 17, 2009 3:23 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|