Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Find Interrupt on Change PIN

Status
Not open for further replies.

M.Rehan

Full Member level 2
Joined
Feb 10, 2016
Messages
129
Helped
2
Reputation
66
Reaction score
33
Trophy points
28
Activity points
972
How to find which on which PIN interrupt has occurred of PORTB <RB4:RB7>
All four pins interrupt on change PIN have single Flag RBIF
I studied this document but couldn't understand assembly language

https://ww1.microchip.com/downloads/en/AppNotes/00566b.pdf


Can someone explain in MikroC code

PIC 16F887
MikroC
 

You check like this...

Code:
if(RBIF_bit && RB4_bit) {

}

if(RBIF_bit && !RB4_bit) {

}
 

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.
 

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

explain in c syntex
 

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.
 
  • Like
Reactions: M.Rehan

    M.Rehan

    Points: 2
    Helpful Answer Positive Rating
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.
 
  • Like
Reactions: M.Rehan

    M.Rehan

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top