- Name:
- write
- Syntax:
-
WRITE location,data ,data, WORD wordvariable...
Location - is a variable/constant specifying a byte-wise address (0-255).
Data - is a variable/constant which provides the data byte to be written. To use a word variable the keyword WORD must be used before the wordvariable.
- Description:
-
Write byte data content into data memory.
The write command allows byte data to be written into the microcontroller's internal 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, 08M2, 14M, 18, 18M and 18M2 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. See the EEPROM command for more details.
When word variables are used (with the keyword WORD) the two bytes of the word are saved/retrieved in a little endian manner (ie low byte at address, high byte at address + 1)
Write to EEPROM
Receive serial data, and write it to EEPROM locations 0 to 63
- Code Example:
-
main: for b0 = 0 to 63 ; start a loop serin C.6,N2400,b1 ; receive serial value write b0,b1 ; write value of b1 into location specified by value in b0 next b0 ; next loop
Copy Code Submit an Example
Write word variables to EEPROM
This program will store the contents of two word variables in Data EEPROM. The w0 variable is written to locations 0 and 1 while the w1 variable is written to locations 2 and 3. As w0 is formed from b0 and b1, w1 is formed from b2 and b3, the next unused byte variable is b4. The b4 variable is used to specify the location within EEPROM to write to. Note that the b4 variable has to be increased by 2 to write word variables to sequential locations in EEPROM as each word variable stored uses two consecutive bytes of storage.
- Code Example:
-
let w0 = $1234 ; w0 holds value $1234 let w1 = $ABCD ; w0 holds value $ABCD let b4 = 0 ; write w0 to location 0 and 1 write b4, word w0 let b4 = b4 + 2 ; write w1 to location 2 and 3 write b4, word w1 ; data eeprom now holds loc data ; 0 $34 w0 lsb (b0) ; 1 $12 w0 msb (b1) ; 2 $CD w1 lsb (b2) ; 3 $AB w2 msb (b3) end
Copy Code Submit an Example
Submit Your Own Code!
You must be logged in to submit code examples. Login now.