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

PIC12F683 in SLEEP Mode

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PIC12F683 in SLEEP Mode
PostPosted: Tue Jul 27, 2010 5:08 pm     Reply with quote

hi

I try put this PIC in sleep mode but it don't go.... or I think it...
Code:

#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, MCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)

#define RAND_MAX 6
#include <STDLIB.H>

void main()
{
output_high(PIN_A5);

delay_ms(2000);
sleep();

}

PS: for example in this program after I call SLEEP() function PIN_A5 don't turnoff?

Someone can help me?

best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 27, 2010 6:05 pm     Reply with quote

Quote:

For example in this program after I call SLEEP() function PIN_A5 don't turnoff?

Download the 12F683 and read the section on Sleep:
Quote:

12.7 Power-Down Mode (Sleep)

It describes what the i/o pins do in Sleep mode. Read it.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jul 28, 2010 7:52 pm     Reply with quote

Hi

For I make an rand sequence I make some like this:
Code:

#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
(...)

while(input(PIN_A3)==1);
do {
   if (n==7) n=0;
   
   n=n+1;
   
   if (input(PIN_A3) == 1) aux=1;
   
   } while ((aux != 1));



switch (n)
{
   case 1 : output_a(0x01);
            break;
   case 2 : output_a(0x02);
            break;
   case 3 : output_a(0x03);
            break;
   case 4 : output_a(0x06);
            break;
   case 5 : output_a(0x07);
            break;
   case 6 : output_a(0x16);
            break;
}

delay_ms(10000);
output_a(0x00);
output_low(PIN_A5);
SLEEP();
}

But my PIN_A3 is MCLR but on fuse I use NOMCLR.

My problem now is, how I can return from SLEEP mode? is possible use reset switch? (attention on fuses because there I have NOMCLR).

best regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 5:51 am     Reply with quote

don't have other way to return from SLEEP MODE if I have MCLR desactivated?

best regards
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 6:55 am     Reply with quote

Your motivation for using sleep mode is completely unclear. In my view, sleep mode makes only sense together with any event that wakes up, in most cases either a watchdog timeout or an external interrupt. But you don't enable a possible wake up event in your code. So a reset would be the only way to restart (not to wake up) the processor. I don't see what it's good for.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 12:18 pm     Reply with quote

Hi

My idea is to save energy.
Can I use PIN_A3 to wake the PIC?
Clicking on PIN_A3 is an event I am doing right?

Best regards
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 2:10 pm     Reply with quote

Yes, you have to enable the GPIO change interrupt for the respective pin.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 4:58 pm     Reply with quote

Hi

How I can make this?

You can give an example?

I try this but give an error on compile.
Code:

#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)

[b]#int_ext
void int_ra3()
{
reset_cpu();
}[/b]

void main()
{
int8 i,aux=0,n=0;
int16 time;

   [b]enable_interrupts(GLOBAL);
   ext_int_edge(H_TO_L);     
   enable_interrupts(INT_EXT);[/b]


while(input(PIN_A3)==1);

do {
   
   if (n==7) n=0;
   n=n+1;
   
   if (input(PIN_A3) == 1) aux=1;
   
   } while ((aux != 1));

switch (n)
{
   case 1 : output_a(0x01);
            break;
   case 2 : output_a(0x02);
            break;
   case 3 : output_a(0x03);
            break;
   case 4 : output_a(0x06);
            break;
   case 5 : output_a(0x07);
            break;
   case 6 : output_a(0x16);
            break;
}

delay_ms(10000);
output_a(0x00);
output_low(PIN_A5);

SLEEP();

//while(input(PIN_A3)==1);
//reset_cpu();
}


best regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 5:52 pm     Reply with quote

hi

Thanks all

Problem is now solve...
Code:

#int_ra
void int_isr(void)
{
}


void main()
{
int8 i,aux=0,n=0;
int16 time;

enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
disable_interrupts(INT_RA3);


(....)

enable_interrupts(INT_RA3);
SLEEP();

This syntax stay correct on sleep mode use?

best 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