View previous topic :: View next topic |
Author |
Message |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
Setting the OPTION register - 12f508 |
Posted: Tue May 10, 2011 5:42 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 10, 2011 7:20 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Wed May 11, 2011 11:04 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Wed May 11, 2011 12:39 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Wed May 11, 2011 3:15 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|