View previous topic :: View next topic |
Author |
Message |
danspage
Joined: 14 Sep 2005 Posts: 8
|
variable |
Posted: Thu Sep 15, 2005 11:10 am |
|
|
How do I keep a variables value when the PIC goes to sleep and then is
woke up on pin change?
PIC 12C508
Thanks! |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Thu Sep 15, 2005 11:15 am |
|
|
The RAM is retained during sleep as long as you don't reset. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 15, 2005 11:40 am |
|
|
The problem is that the 12C508 does a reset when it wakes up from
sleep. Read section 8.9.2 in the data sheet:
Quote: |
8.9.2 WAKE-UP FROM SLEEP
The device can wake-up from SLEEP through one of
the following events:
1. An external reset input on GP3/MCLR/VPP pin,
when configured as MCLR.
2. A Watchdog Timer time-out reset (if WDT was
enabled).
3. A change on input pin GP0, GP1, or GP3/
MCLR/VPP when wake-up on change is
enabled.
These events cause a device reset.
|
I looked in the data sheet and I can't find any statement on
the condition of RAM after a wake-up from sleep reset.
It's probably unchanged. So you can probably preserve
the contents of RAM, by just not using a #zero_ram statement.
If you have a #zero_ram statement in your program, then remove it. |
|
|
DP Guest
|
|
Posted: Thu Sep 15, 2005 12:39 pm |
|
|
I just declared an int, and everything was fine.
I thought a first I had to declare a static int, but that didn't seem to work.
Thanks!
|
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Thu Sep 15, 2005 1:38 pm |
|
|
Hello
That statement about register values at reset is at page 38:
Quote: |
Some registers are not reset in any way; they are
unknown on POR and unchanged in any other reset.
Most other registers are reset to reset state on power on
reset (POR), MCLR, WDT or wake-up on pin
change reset during normal operation. They are not
affected by a WDT reset during SLEEP or MCLR reset
during SLEEP, since these resets are viewed as
resumption of normal operation.
|
mfg
Felix |
|
|
|