Sleep mode

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
gatoulisss
Posts: 1
Joined: 29 Oct 2015 10:52

Sleep mode

#1 Post by gatoulisss » 29 Oct 2015 11:03

hello everyone!

im very new to all this so i need your help!
i built my own alarm system witch is powered with 9v battery the circuit has a pic16f88 mcu, 3 reed switch, 1 on-off switch and a buzzer to sound the alarm.
i have problem with the battery life so after some search i found out that i have to change the LM7805 regulator and that i can put my mcu in sleep mode so ican save more power.
can anybody help me with this? how i can enter sleep mode and wake up when one of the sensors become from 0 to 1?

for example in this code how i could use sleep mode and wake up when the sensor becomes from 0 to 1? (is just a code to understand how to use sleep mode, ports and everything else can change as needed for the sleep mode)

Code: Select all

void main() {
osccon=0x60;
ansel=0;
 TRISB.F7 = 0;        //buzzer output
 TRISA.F0 = 1;       // one of the sensors
 PORTB.F7 = 0;
 for(;;){

 if   (PORTA.F0==0) {
  delay_ms(3000);       //wait some time before th alert
  while(PORTA.F0==0)
  {
    PORTB.F7 = 1;           //alert

  }
}
else {
PORTB.F7 = 0;
}
}
}
thank you!

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: Sleep mode

#2 Post by Aleksandar.Mitrovic » 30 Oct 2015 14:49

Hi,

The device can wake-up from Sleep through one of the following events:
1. External Reset input on MCLR pin.
2. Watchdog Timer wake-up (if WDT was enabled).
3. Interrupt from INT pin, RB port change or a
peripheral interrupt.

Take a look at the datasheet of this microcontroller for the correct settings, page 50 (EXITING SLEEP WITH AN INTERRUPT) :
http://ww1.microchip.com/downloads/en/D ... 30487D.pdf

Also, on the page 140 you can find more information how to set and enable interrupts.

I'm suggesting you to try search our forum or LibStock website and try to find some example for how to put MCU to sleep:
www.libstock.com

Best regards,
Aleksandar

Post Reply

Return to “Library Development Discussion”