hippy
Ex-Staff (retired)
Here's an early Christmas present.
A neat trick for preserving data when a RESET command is executed and resetting that data to a known initial value when an actual power-cycle reset occurs. All without using EEPROM storage -
Works for an 08M2, probably works for other M2's, and can likely be made to work with X2's with some changes. It has to be run on a physical chip as simulation does not fully simulate SFR registers.
It will likely start with a random value after a download but turning it off and on will get it doing what it's meant to.
A neat trick for preserving data when a RESET command is executed and resetting that data to a known initial value when an actual power-cycle reset occurs. All without using EEPROM storage -
Code:
#Picaxe 08M2
#Terminal 4800
#No_Data
Symbol ADRESL = $3B ; $09B
Symbol ADRESH = $3C ; $09C
Symbol BORCON = $56 ; $116
PowerOnReset:
Gosub LoadW0
SerTxd( "Restarted: w0 = ", #w0, CR, LF )
w0 = w0 + 1
Gosub SaveW0
Pause 1000
Reset
LoadW0:
PeekSfr BORCON, b0
If bit6 = 0 Then
SerTxd( "Power-On Reset", CR, LF )
w0 = 0
Else
PeekSfr ADRESL, b0
PeekSfr ADRESH, b1
PokeSfr BORCON, $81
End If
Return
SaveW0:
PokeSfr ADRESL, b0
PokeSfr ADRESH, b1
PokeSfr BORCON, $C1
Return
It will likely start with a random value after a download but turning it off and on will get it doing what it's meant to.