Poke variable changes on power down/up

erdc

Member
If you first run this code, you will get “b1 = 22”

if b0 = 0 then poke 200, 22
endif
peek 200, b1
sertxd("b1 = ",#b1,cr,lf)

Then disconnect the power for a second, and then apply back the power and you will get “b1 = 22”

Now enter in this code and run it, and you still will get “b1 = 22”.

if b0 = 1 then poke 200, 22 'only b0 = 1 has been changed
endif
peek 200, b1
sertxd("b1 = ",#b1,cr,lf)

But when you now disconect the power for a second, and then apply back the power you will get “b1 = 4”

This was done on 28X Ver. 7.8 chip

Edited by - erdc on 02/03/2007 15:28:13
 

hippy

Technical Support
Staff member
What happens is that the PICAXE doesn't clear SFR at $C0..$EF/$FF when it powers up or resets ( 200 = $C8 ) so, providing there is some residual voltage, the contents of SFR remain intact with power removed.

How well it works and for how long depends upon how quickly that residual voltage is drained away.

http://www.rev-ed.co.uk/picaxe/forum/Topic.asp?topic_id=4508
 

erdc

Member
This is very good to know. I have been going on the assumption that these were cleared on power down. I will make sure to hard code in zeros to any register that is critical.

Does/could this scenario also happens to the variables (b0,b1,,,b12)?
 

hippy

Technical Support
Staff member
The variables b0..b13 are placed below $80 so will always get cleared, it's only $C0 and above which doesn't get cleared.

I hadn't tested a 28X so it's good to know that behaviour is consistent across the PICAXE range; thanks.

The forthcoming X2's are based on PICmicro 18F's so those are likely to behave differently. Lots of fun to be had 'hacking' ( in the 'quest for knowledge; sense ) I suspect when they do arrive.
 

slurp

Senior Member
I'd guess a lot of the useful peek and poke tips will still work. That flag tip was an excellent one (and put me right on other PICs) has anyone made a list online?

Was thinking it's something I'll have to start recording as an unofficial FAQ...

regards,
colin
 
Top