PDA

View Full Version : Help with PORTB Interrupt On Change Please



Aussie Barry
- 11th September 2017, 10:26
Hi All,

I am looking to use PORTB Interrupt On Change on a PIC18F26J50 but can't get my head around how to determine which pin (PORTB.4 - 7) caused the interrupt.
I would like to set up four momentary action switches to each of the four PORTB IOC pins (with associated pull up resistors) and then action different sections of code depending on which switch was activated.
I have searched the FORUM looking for examples but haven't found anything which answers my questions.

Any assistance and/or guidance would be greatly appreciated.

Cheers
Barry
VK2XBP

richard
- 11th September 2017, 11:07
one way



oldportb var byte
pbchange var byte


in main before isr enabled
oldportb=portb





in isr {portb must have changed to get here}


pbchange = portb ^ oldportb ; xor portb with last known state and set bits that changed

oldportb=portb ;update state
pbchange=pbchange>>4 ; shift result to low byte

int returm

Aussie Barry
- 11th September 2017, 11:57
Thanks Richard.

It was the xor process that I was missing.

Cheers
Barry
VK2XBP