+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Full Member level 2
    Points: 916, Level: 6
    M.Rehan's Avatar
    Join Date
    Feb 2016
    Posts
    129
    Helped
    33 / 33
    Points
    916
    Level
    6

    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

    http://ww1.microchip.com/downloads/e...tes/00566b.pdf


    Can someone explain in MikroC code

    PIC 16F887
    MikroC

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 3
    Points: 3,996, Level: 14

    Join Date
    Aug 2015
    Posts
    773
    Helped
    142 / 142
    Points
    3,996
    Level
    14

    Re: Find Interrupt on Change PIN

    You check like this...

    Code:
    if(RBIF_bit && RB4_bit) {
    
    }
    
    if(RBIF_bit && !RB4_bit) {
    
    }



    •   AltAdvertisment

        
       

  3. #3
    Super Moderator
    Points: 75,009, Level: 66
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,292
    Helped
    4079 / 4079
    Points
    75,009
    Level
    66

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisment

        
       

  4. #4
    Full Member level 2
    Points: 916, Level: 6
    M.Rehan's Avatar
    Join Date
    Feb 2016
    Posts
    129
    Helped
    33 / 33
    Points
    916
    Level
    6

    Re: Find Interrupt on Change PIN

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

    explain in c syntex



  5. #5
    Super Moderator
    Points: 75,009, Level: 66
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,292
    Helped
    4079 / 4079
    Points
    75,009
    Level
    66

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  6. #6
    Super Moderator
    Points: 249,738, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,476
    Helped
    13213 / 13213
    Points
    249,738
    Level
    100

    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.

--[[ ]]--