CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC12F675 + Sleep + External Interrupt Wakeup

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
heisenberg



Joined: 12 Nov 2010
Posts: 1

View user's profile Send private message

PIC12F675 + Sleep + External Interrupt Wakeup
PostPosted: Fri Nov 12, 2010 2:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 12, 2010 3:21 pm     Reply with quote

See the examples by ckielstra in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=28447
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Nov 12, 2010 3:43 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group