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;
}
}
}