View previous topic :: View next topic |
Author |
Message |
heisenberg
Joined: 12 Nov 2010 Posts: 1
|
PIC12F675 + Sleep + External Interrupt Wakeup |
Posted: Fri Nov 12, 2010 2:36 pm |
|
|
I'm doing a bias lighting system for my monitor and TV using two PIC12F675s and some LEDs and a light sensor. Two different push buttons control whether to turn the system on or off depending if the room is dark. I want to put the MCUs into sleep mode instead of having it poll the push buttons and use the ON button as an external interrupt to kick it out of sleep and loop back to the beginning of the code. I don't understand how to use sleep and external interrupts properly.
Flow:
[nothing happening]->[sleep]->[room is dark and ON button pushed]->[exit sleep mode, turn on LEDs]->[off button pushed, turn off LEDs]->[sleep]...
Schematic:
Code:
Code: |
#include <12f675.h>
#fuses INTRC_IO, NOWDT, NOMCLR
#use delay(clock=4000000)
#bit INTF = 0xB.1
//PIN_A0 = LED
//PIN_A1 = LIGHT
//PIN_A2 = ON
//PIN_A3 = OFF
//PIN_A4 = CONTROL
//PIN_A5 = LED
void main()
{
int on, off, adc;
//ext_int_edge(H_TO_L);
//INTF = 0;
//enable_interrupts(INT_EXT);
//enable_interrupts(GLOBAL);
while(1)
{
setup_adc_ports(sAN1);
setup_adc(ADC_CLOCK_INTERNAL);
delay_ms(100);
set_adc_channel(1);
adc = read_adc();
delay_ms(10);
//ON button pushed
if(input(PIN_A2) == 0)
on = 1;
//OFF button pushed
else if (input(PIN_A3) == 0)
off = 1;
else
{
on = 0;
off = 0;
}
//ON button pushed and room is dark
if((adc < 50) && (on == 1))
{
output_HIGH(PIN_A5);
output_HIGH(PIN_A4);
output_HIGH(PIN_A0);
}
//OFF button pushed or room is bright
else if ((off == 1) || (adc > 50))
{
output_LOW(PIN_A5);
output_LOW(PIN_A4);
output_LOW(PIN_A0);
}
//Waiting.....go to sleep unless ON button is pushed
else
{
//INTF = 0;
//sleep();
}
}
}
|
The code for the second PIC isn't important. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Nov 12, 2010 3:43 pm |
|
|
Quote: |
I don't understand how to use sleep and external interrupts properly.
|
If you have achieved to run this project properly, see ex-wakep.c in the examples folder, it should be
very straightforward to implement in your application.
Regards |
|
|
|