Reset variables when changing SLOT

matchbox

Senior Member
Is it a reasonable practice to Reset variables on a SLOT before the new slot is entered?

I am using a 14M2 and want to use slot 0 and slot 1 as independent programs. Because of the way the change between the two takes place (on power up not power down), it isn't easy to do a reset before it leaves the previous slot.
 
Last edited:

Hemi345

Senior Member
You could write a byte to the PICAXE's EEPROM and check that on reset to determine which slot to run. That should be an easy way to reset all variables.
 

inglewoodpete

Senior Member
Is it a reasonable practice to Reset variables on a SLOT before the new slot is entered?

I am using a 14M2 and want to use slot 0 and slot 1 as independent programs. Because of the way the change between the two takes place (on power up not power down), it isn't easy to do a reset before it leaves the previous slot.
I think what you're asking for is the following code, which can be tested in the simulator. You could define it as a macro, so it can be invoked as a single line command in your code.
Rich (BB code):
#PICAXE 14M2
'Open the Code Explorer prior to running this in the simulator
For b0 = 1 To 27 'For simulation, initialise b0 to b27 to non-zero values to demonstrate the zeroising code, further below
   Poke b0, b0
Next b0
' The following code zeros all byte registers and the bPtr
bPtr = 27
Do
   @bPtrDec = 0
Loop Until bPtr = 0
b0 = 0
 

hippy

Technical Support
Staff member
I am using a 14M2 and want to use slot 0 and slot 1 as independent programs. Because of the way the change between the two takes place (on power up not power down), it isn't easy to do a reset before it leaves the previous slot.
It's not clear exactly how you will have things working but you could clear variables and/or RAM before you RUN another slot, or when the other slot starts. The second would be my preference.
 

Aries

New Member
Unless you are relying on variables (b0, w0 etc) being zero at the start of the program (which I would regard as bad practice anyway), it shouldn't be necessary to zero them, because the first reference to such a variable in any program should always be to load it with a value from somewhere else.
 

matchbox

Senior Member
Thank you all for the reply guys. That will do just fine Pete(y)

It just uses a momentary switch to change Slots. Unfortunately this momentary switch is not on an interrupt pin, so it makes clearing more awkward before leaving a previous Slot.
The program has much mirrored code and variables, plus uses RF serial. So it needs many of the bytes and words cleared to prevent issues.
 
Top