Connect with us

pic16f88 sleep and wake on interrupt

Discussion in 'Microcontrollers, Programming and IoT' started by gatoulisss, Jan 4, 2019.

Scroll to continue with content
  1. gatoulisss


    Jan 23, 2015
    hello everyone!

    I need your help, im using mikro c and trying to use sleep mode on a pic16f88 mcu and wake from a interrupt on RB0 pin (internal osc)
    what I want to do is a simple project so I can understand how to use sleep mode, for example:

    I have a sensor on RB0 pin, when this is '1' then a led will blink, when it goes '0' for more than 3secs then the mcu goes to sleep till RB0 goes '1' again and then repeat the process.

    can anyone help me with the code? thank you!
  2. BobK


    Jan 5, 2010
    Don't know the details of MicroC, I use Microchip tools, but it should be pretty simple.

    You need to enable the specific interrupt and enable all interrupts by turning on GIO. Then you sleep. The interrupt will awaken the processor. You need an interrupt handler, but it does not have to do anything, just return. MicroC probably provides a default one that does this.

    Use a counter to represent the 3 seconds. For instance if you blink 3 times per second, you would want to set the counter to 9. Each time through the loop, check RB0. If it is high, set the counter back to 9. If it is low, decrement the counter. If the counter reaches zero, clear the interrupt flag for the RB0 interrupt, then go back to the sleep.

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day