16F88 Wake from SLEEP on Port B change?

Status
Not open for further replies.

MikeMl

Well-Known Member
Most Helpful Member
Programing in C. Where does the program begin executing when a port B pin changes?
Do you have to write an whole ISR? If so, does control pass to the next statement after the SLEEP call by doing a return?
 
Hi Mike,

I may be wrong (it's been awhile) but I believe that if you don't enable global interrupts then program execution resumes at a point after the sleep instruction. In the example below, I believe the program resumes at the delay instruction after wake-up.

Code:
  while(1)
  {
    swnew = portb;                // clear mismatch condition
    intcon.RBIF = 0;              // clear IOC interrupt flag
    sleep();                      //
    nop();                        //
   /*                                                                 *
    *  swnew  ____---____-----___    new switch sample                *
    *  swold  _____---____-----__    switch state latch               *
    *  delta  ____-__-___-____-__    changes, press or release        *
    *  newhi  ____-______-_______    filter out new release bits      *
    *                                                                 */
    delay_us(16);                 // 16-msec debounce interval
    swnew = ~portb;               // sample active lo switches
    swnew &= 0x0F;                // on RB3..RB0 pins
    swnew ^= swold;               // changes, press or release
    swold ^= swnew;               // update switch state latch
    swnew &= swold;               // filter out new release bits
  
    if(swnew.0)                   // if sw0 (RB0) pressed
    {                             //
      ....                        //
    }
    if(swnew.1)                   // if sw1 (RB1) pressed
    {                             //
      ....                        //
    }
    if(swnew.2)                   // if sw2 (RB2) pressed
    {                             //
      ....                        //
    }
    if(swnew.3)                   // if sw3 (RB3) pressed
    {                             //
      ....                        //
    }
  }
Now if you do implement an ISR then program execution will go to the ISR after waking up with an IOC interrupt and the "return from interrupt" should resume program execution after the sleep() instruction (you still need a nop() instruction after the sleep() instruction).

Please correct me if I'm wrong guys?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…