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 support@ccsinfo.com

Setting the OPTION register - 12f508

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



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

Setting the OPTION register - 12f508
PostPosted: Tue May 10, 2011 5:42 pm     Reply with quote

I'm experimenting with the wake_on_pin_change function of the 12f508, but I see no setting for this in the header file. I decided to hunt down the register and manually set it, but I'm not too keen with linking data sheet bit tables to code. I can't seem to find the address for the 'OPTION' register. I need to set bit 7 of this register in order to use this function. Am I over looking something here? I'm referring to the data sheet, page 22 (24 pdf). I see it says "By executing the OPTION instruction, the contents of the W register will be transferred to the OPTION register.
A Reset sets the OPTION<7:0> bits." but unfortunately I don't understand how to execute an option instruction. Any clues?

Also I do see in the header file "#ifndef PIN_CHANGE_FROM_SLEEP
#define PIN_CHANGE_FROM_SLEEP 0x90 // for 508 and 509 only", but after doing a search I can't find out how this benefits me. I'm sure it's something simple but I'm having the hardest time solving this.
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 10, 2011 7:20 pm     Reply with quote

Use the set_options() macro in ex_macro.c. Copy and paste the macro
into your program. Put it above main(). Then call it, with your desired
value for the OPTION register. Consult the PIC data sheet to decide on
the correct value for your application. Here's the file location:
Quote:

c:\program files\picc\examples\ex_macro.c


Example thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=33336
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed May 11, 2011 11:04 am     Reply with quote

Thanks PCM, I've compiled this program and am about to test.

Code:
#include "12f508.h"
#use delay(clock=4000000)
#Fuses INTRC,NOWDT,NOPROTECT,NOMCLR
#use RS232(BAUD=2400,FORCE_SW,XMIT=pin_b5)

int16 sleeptimer=0;
int1 PinChangeFlag;

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}
                             
#byte STATUS = 0x003
#bit GPWUF = STATUS.7

#define txen pin_b4
#define inc pin_b2
#define dec pin_b1
#define off pin_b0

void main()
{
   set_options(0x38); // 00111000 = 56 = 0x38
   PinChangeFlag = GPWUF;
   while(1)
   {
      if(PinChangeFlag)
      {
         if(!input(inc))
         {
            output_high(txen);
            sleeptimer=0;
            putc(20);
         }
         
         if(!input(dec))
         {
            output_high(txen);
            sleeptimer=0;
            putc(30);
         }
         
         if(!input(off))
         {
            output_high(txen);
            sleeptimer=0;
            putc(40);
         }
      }
     
      if(sleeptimer>500)
      {
         output_low(txen);
         sleeptimer=0;
         sleep();
         delay_cycles(1);
      }
      else
      {
         sleeptimer++;
      }
     
      delay_ms(5);
   }
}


I'll post my result as soon as im finished testing.
_________________
Vinnie Ryan


Last edited by vinniewryan on Wed May 11, 2011 12:39 pm; edited 1 time in total
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed May 11, 2011 12:39 pm     Reply with quote

Just got done testing. The program works perfectly! Though when I enter sleep mode the current drain is .24mah where it should be closer to 100na according to the datasheet. This is a problem as it's in a remote controller powered by a 3V lithium.

Thanks for the quick help PCM!
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 11, 2011 1:00 pm     Reply with quote

Here are some threads on reducing sleep current:
http://www.ccsinfo.com/forum/viewtopic.php?t=45094
http://www.ccsinfo.com/forum/viewtopic.php?t=44141
http://www.ccsinfo.com/forum/viewtopic.php?t=22320
http://www.ccsinfo.com/forum/viewtopic.php?t=17199
http://www.ccsinfo.com/forum/viewtopic.php?t=22402
http://www.ccsinfo.com/forum/viewtopic.php?t=19006
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed May 11, 2011 3:15 pm     Reply with quote

Thanks for the links. I found that setting my rs-232 pin 'low' before entering sleep() fixed the problem. Now my sleep current is so low that my meter can't even measure it. < 0.001MAh
_________________
Vinnie Ryan
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