English
Language : 

C8051F850-C-GM Datasheet, PDF (69/328 Pages) Silicon Laboratories – Low-Cost 8-bit MCU Family with up to 8 kB of Flash
10.2. Programming the Flash Memory
Writes to flash memory clear bits from logic 1 to logic 0, and can be performed on single byte locations.
Flash erasures set bits back to logic 1, and occur only on full pages. The write and erase operations are
automatically timed by hardware for proper execution; data polling to determine the end of the write/erase
operation is not required. Code execution is stalled during a flash write/erase operation.
The simplest means of programming the flash memory is through the C2 interface using programming
tools provided by Silicon Labs or a third party vendor. This is the only means for programming a non-
initialized device.
To ensure the integrity of flash contents, it is strongly recommended that the on-chip supply monitor be
enabled in any system that includes code that writes and/or erases flash memory from software.
10.2.1. Flash Lock and Key Functions
Flash writes and erases by user software are protected with a lock and key function. The Flash Lock and
Key Register (FLKEY) must be written with the correct key codes, in sequence, before flash operations
may be performed. The key codes are: 0xA5, 0xF1. The timing does not matter, but the codes must be
written in order. If the key codes are written out of order, or the wrong codes are written, flash writes and
erases will be disabled until the next system reset. Flash writes and erases will also be disabled if a flash
write or erase is attempted before the key codes have been written properly. The flash lock resets after
each write or erase; the key codes must be written again before a following flash operation can be
performed.
10.2.2. Flash Erase Procedure
The flash memory can be programmed by software using the MOVX write instruction with the address and
data byte to be programmed provided as normal operands. Before writing to flash memory using MOVX,
flash write operations must be enabled by: (1) setting the PSWE Program Store Write Enable bit in the
PSCTL register to logic 1 (this directs the MOVX writes to target flash memory); and (2) Writing the flash
key codes in sequence to the Flash Lock register (FLKEY). The PSWE bit remains set until cleared by
software.
A write to flash memory can clear bits to logic 0 but cannot set them; only an erase operation can set bits
to logic 1 in flash. A byte location to be programmed should be erased before a new value is written.
Erase operation applies to an entire page (setting all bytes in the page to 0xFF). To erase an entire page,
perform the following steps:
1. Disable interrupts (recommended).
2. Set the PSEE bit (register PSCTL).
3. Set the PSWE bit (register PSCTL).
4. Write the first key code to FLKEY: 0xA5.
5. Write the second key code to FLKEY: 0xF1.
6. Using the MOVX instruction, write a data byte to any location within the page to be erased.
7. Clear the PSWE and PSEE bits.
10.2.3. Flash Write Procedure
Flash bytes are programmed by software with the following sequence:
1. Disable interrupts (recommended).
2. Erase the flash page containing the target location, as described in Section 10.2.2.
3. Set the PSWE bit (register PSCTL).
4. Clear the PSEE bit (register PSCTL).
5. Write the first key code to FLKEY: 0xA5.
6. Write the second key code to FLKEY: 0xF1.
7. Using the MOVX instruction, write a single data byte to the desired location within the desired
Rev. 1.0
59