English
Language : 

C8051F120 Datasheet, PDF (202/356 Pages) Silicon Laboratories – Mixed Signal ISP Flash MCU Family
C8051F120/1/2/3/4/5/6/7
C8051F130/1/2/3
15.1.3. Writing FLASH Memory From Software
Bytes in FLASH memory can be written one byte at a time, or in small blocks. The CHBLKW bit in register
CCH0CN (Figure 16.4) controls whether a single byte or a block of bytes is written to FLASH during a write
operation. When CHBLKW is cleared to ‘0’, the FLASH will be written one byte at a time. When CHBLKW
is set to ‘1’, the FLASH will be written in blocks of four bytes for addresses in code space, or blocks of two
bytes for addresses in the Scratchpad area. Block writes are performed in the same amount of time as sin-
gle byte writes, which can save time when storing large amounts of data to FLASH memory.
For single-byte writes to FLASH, bytes are written individually, and the FLASH write is performed after
each MOVX write instruction. The recommended procedure for writing FLASH in single bytes is:
Step 1. Disable interrupts.
Step 2. Clear CHBLKW (CCH0CN.0) to select single-byte write mode.
Step 3. If writing to bytes in Bank 1, Bank 2, or Bank 3, set the COBANK bits (PSBANK.5-4) for
the appropriate bank.
Step 4. If writing to bytes in the Scratchpad area, set the SFLE bit (PSCTL.2).
Step 5. Set FLWE (FLSCL.0) to enable FLASH writes/erases via user software.
Step 6. Set PSWE (PSCTL.0) to redirect MOVX commands to write to FLASH.
Step 7. Use the MOVX instruction to write a data byte to the desired location (repeat as
necessary).
Step 8. Clear the PSWE bit to redirect MOVX commands to the XRAM data space.
Step 9. Clear the FLWE bit, to disable FLASH writes/erases.
Step 10. If writing to bytes in the Scratchpad area, clear the SFLE bit.
Step 11. Re-enable interrupts.
For block FLASH writes, the FLASH write procedure is only performed after the last byte of each block is
written with the MOVX write instruction. When writing to addresses located in any of the four code banks,
a FLASH write block is four bytes long, from addresses ending in 00b to addresses ending in 11b. Writes
must be performed sequentially (i.e. addresses ending in 00b, 01b, 10b, and 11b must be written in order).
The FLASH write will be performed following the MOVX write that targets the address ending in 11b. When
writing to addresses located in the FLASH Scratchpad area, a FLASH block is two bytes long, from
addresses ending in 0b to addresses ending in 1b. The FLASH write will be performed following the MOVX
write that targets the address ending in 1b. If any bytes in the block do not need to be updated in FLASH,
they should be written to 0xFF. The recommended procedure for writing FLASH in blocks is:
Step 1. Disable interrupts.
Step 2. Set CHBLKW (CCH0CN.0) to select block write mode.
Step 3. If writing to bytes in Bank 1, Bank 2, or Bank 3, set the COBANK bits (PSBANK.5-4) for
the appropriate bank.
Step 4. If writing to bytes in the Scratchpad area, set the SFLE bit (PSCTL.2).
Step 5. Set FLWE (FLSCL.0) to enable FLASH writes/erases via user software.
Step 6. Set PSWE (PSCTL.0) to redirect MOVX commands to write to FLASH.
Step 7. Use the MOVX instruction to write data bytes to the desired block. The data bytes must
be written sequentially, and the last byte written must be the high byte of the block (see text for
details, repeat as necessary).
Step 8. Clear the PSWE bit to redirect MOVX commands to the XRAM data space.
Step 9. Clear the FLWE bit, to disable FLASH writes/erases.
Step 10. If writing to bytes in the Scratchpad area, clear the SFLE bit.
Step 11. Re-enable interrupts.
204
Rev. 1.3