Cwrite
Syntax
Cwrite Address, [ Variable {, Variable…} ]
Overview
Write data to anywhere in flash memory on devices that support it.
Parameters
Variable can be a constant, variable, or expression. Address is a constant, variable, label, or expression that represents any valid flash memory address
Example
' Write to memory location 2000+ within the PICmicro
Device = 16F877
' Choose the PICmicro
Declare Xtal = 4
Dim MyByte as Byte = 234
Dim MyWord as Word = 1043
Dim wAddress as Word = 2000
' wAddress now holds the base address
Cwrite wAddress, [10, MyByte, MyWord] ' Write to address 2000 +
Org 2000
Notes
The Cwrite command takes advantage of the self-modifying feature that is available in most devices.
If a Word size variable is used as the assignment, then a 14-bit Word will be written. If a Byte sized variable is used as the assignment, then 8-bits will be written.
Because the 14-bit core devices are only capable of holding 14 bits to a Word, values greater than 16383 ($3FFF) cannot be written. However, the 18F devices may hold values up to 65535 ($FFFF).
The configuration fuse setting WRTE must be enabled before Cdata, Cread, and Cwrite may be used, this is the default setting. This enables the self-modifying feature. If the Config directive is used, then the WRTE_ON fuse setting must be included in the list: -
Config WDT_ON, XT_OSC, WRTE_ON
Org is actually an assembler directive, so the compiler has no control over it, and if using procedures, it will cause assembler errors, or the program not to work correctly. Only use the Org directive if you know what the underlying assembler code, that the compiler creates, is doing.