08M, 14M, 20M Read & Write commands

Mookitty

New Member
I've searched but "read" or "write" as terms bring up most of the posts on the forum. >_<

Manual 2, page 184:
The write command allows byte data to be written into the microcontrollers data memory. The contents of this memory is not lost when the power is removed. However the data is updated (with the EEPROM command specified data) upon a new download. To read the data during a program use the read command.

With the PICAXE-08, 08M, 14M and 18 the data memory is shared with program memory. Therefore only unused bytes may be used within a program. To establish the length of the program use ‘Check Syntax’ from the PICAXE menu. This will report the length of program. Available data addresses can then be used as follows:

PICAXE-08, 18 0 to (127 - number of used bytes)
PICAXE-08M, 14M, 20M 0 to (255 - number of used bytes)
Supposing I want to "set aside" the last 6 bytes (250 to 255) by making sure the program is 249 bytes or less. Then my program has the write command in the init section which fills those values. I then power up the chip and the program runs once, setting the values. Sample code:

Code:
init:
    write 250, "a" 
    write 251, "b" 
    write 252, "c" 
    write 253, "d" 
    write 254, "e" 
    write 255, "f" 
main:
    ....                'main program body
Now for future downloads, I comment out the write commands, and download and test program changes. I understand that the "reserved" bytes hold their value across power ups, the same as the main program. But will they survive repeated downloads, where the main program body doesn't "touch" them?

I'd hate to have the init code run every power up, that would be unnecessary. I'd like to set them, then re-download the same program with the writes commented out. I think that's possible, if I understand the bolded portion of the manual quote above.

Any help is appreciated, thanks.
 

hippy

Ex-Staff (retired)
The EEPROM command is available to reserve and initialise non-volatile data storage, so you could use -

EEPROM ("a","b","c","d","e")

That will load the data eeprom with those values on download ready to be read by the READ command and changed by WRITE.

Non-volatile data is preserved across resets and power-cycles but not across downloads, that's just the way it is because of the way the memory has to be used and this usually works well for most PICAXE users.

With EEPROM doing the job of your multiple WRITE initialisation ( and using no extra code space ), this may solve your problem.

If you do need to retain data despite downloads, external I2C Eeprom is the best option there and the 18X and X1 PICAXE's are best suited for that having I2C commands.
 

inglewoodpete

Senior Member
Note the the EEPROM 'area' for data starts at 0. I think Rev-Ed wanted to make it easier for beginners, and for code portability between the various chips. 'Old' microprocessor programmers like myself think too much.

My initial code a few years ago for testing EEPROM in an 08M involved writing to locations 255, 254 etc. It stopped the PICAXE promptly by overwriting the code!

Then I read the manual :)
 
Last edited:
Top