Texas Instruments MSC1210 User Manual

Page 192

Advertising
background image

Flash Memory as Data Memory

15-10

15.5 Flash Memory as Data Memory

If so configured in HCR0, some portion of flash memory can be accessed by
your application program as flash data memory. The amount of flash memory
that is partitioned as flash data memory is controlled by the low 3 bits of HCR0.
Please see Section 15.1.1.1, Hardware Configuration Register 0, for details.

When some amount of flash memory is partitioned as flash data memory, the
program may read, update, and store information in nonvolatile memory that
will survive power-off situations. That makes the flash data memory a useful
area to store configuration or data logging information.

The following program illustrates how flash data memory may be read and up-
dated.

Note:

The MSEC and USEC SFRs must be correctly set prior to erasing or writing
to flash memory.

Within the infinite

while()

loop, the program first reads flash data memory.

This is accomplished directly by reading XRAM memory. This is accomplished
in this C program by using the pFlashPage pointer—it is accomplished in
assembly language using the MOVX instruction.

After reading flash memory, it increments the value of the first byte of the
memory block read by one. The call to page_erase()is a call to the routine in
boot ROM that erases the requested block of memory. Thereafter, it makes re-
peated calls to write_flash_chk to write the buffer back to the block of flash data
memory one byte at a time.

The infinite loop continues by displaying the result of the writes to flash data
memory (0 = Success) and the updated value contained in the buffer as read
from flash data memory via the pFlashPage pointer. It then prompts the user
to hit any key, after which the loop will repeat itself and the first byte of the buffer
will again be incremented.

#include <stdio.h>

#include <reg1210.h>

#include ”rom1210.h”

// define the page we want to modify

#define PAGE_START 0x0400

#define PAGE_SIZE 0x80

// define a pointer to this page

char xdata * pFlashPage;

// define a RAM area as a buffer to hold one page

char xdata Buffer[PAGE_SIZE];

int main()

{

char Result;

Advertising