Maker Pro
Maker Pro

pic16f88 sleep and wake on interrupt

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!
 
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.

Bob
 
Top