PortB change interruption

Discussion in 'Programmer's Corner' started by a.mahesh.mrt, Feb 26, 2012.

  1. a.mahesh.mrt

    Thread Starter New Member

    Feb 26, 2012
    I'm currently working on a project which try to detect the change of the PORTB using PIC16f877.but i was not able to detect that.does anyone know about the portB change interruption routine please help me.
  2. be80be

    Senior Member

    Jul 5, 2008
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    To use IOC features you must init the INTCON register: GIE (general) and the RBIE (RB Port Change Interrupt Enable bit) must be set.

    The your ISR must first read port B to clear the mismatch, then the INTCON RBIF RB Port Change Interrupt Flag bit must be cleared. If another change occurs the change interrupt will fire immediately when you exit the ISR.

    The read gives you the current value. Note for pin glitches this may be a different state then the one that fired the ISR.

    ANY read or write to Port B affects the change state, and there is a small but non-zero chance accessing the port outside of the ISR will result in a missed change. There are ways to code against that if need be.