# Find Interrupt on Change PIN

1. ## Find Interrupt on Change PIN

How to find which on which PIN interrupt has occurred of PORTB
All four pins interrupt on change PIN have single Flag RBIF
I studied this document but couldn't understand assembly language

Can someone explain in MikroC code

PIC 16F887
MikroC

•

2. ## Re: Find Interrupt on Change PIN

You check like this...

Code:
```if(RBIF_bit && RB4_bit) {

}

if(RBIF_bit && !RB4_bit) {

}```

•

3. ## Re: Find Interrupt on Change PIN

I would do it differently. Read the port and store the value, lets call it "OldPortValue" then when the IOC interrupt occurs use "difference = (OldPortValue ^ PORTB);" that leaves any bit that has changed a '1' in difference and any bit that didn't change a '0'.

Brian.

•

4. ## Re: Find Interrupt on Change PIN

What if one PORT pin is changed from 1 to 0?

explain in c syntex

5. ## Re: Find Interrupt on Change PIN

It will still show using my method.

The " ^ " symbol is the exclusive OR logic function in C. It takes two 8-bit values and returns an 8-bit result which has a '1' if the bit in one value is different to the same bit in the other. It s the difference that makes the bit '1', it doesn't matter if the bit went high or low. For example:

old port bits = 00001111
new port bits = 01001111
result = 01000000 because bit 6 changed

old port bits = 10101010
new port bits = 10101000
result = 00000010 because bit 1 changed

So if you sample the port before and after the IOC, exor the two values, the result is a map of which bit or bits changed.

Brian.

1 members found this post helpful.

•

6. ## Re: Find Interrupt on Change PIN

explain in c syntax
I believe, betwixt did.

Port B IOC feature doesn't distinguish between 0->1 and 1->0 change. If you want direction selective action, make respective logic combination of "old" and "new" port value.

I have a problem with the method suggested in AN566. As far as I understand, the bit test operations performed directly on port B will reset a mismatch condition caused by additional input transitions without latching the new state. To avoid loosing input events, you'll read the port state only once per interrupt.

There's still a chance that short input glitches trigger a change interrupt without showing an actual change in the port state. These events can't be assigned to a port pin and must be ignored.

1 members found this post helpful.

--[[ ]]--