Texas Instruments MSC1210 User Manual

Page 193

Advertising
background image

Flash Memory as Data Memory

15-11

Advanced Topics

unsigned char i;

// synchronize baud rate

autobaud();

// Set the pointer to the beginning of the page to modify

pFlashPage = (char xdata * ) PAGE_START;

// before writing the flash, we have to initialize

// the usec and msec SFRs because the flash programming

// routines rely on these SFRs

USEC = 12−1; // assume a 12 MHz clock

MSEC = 12000−1;

while(1)

{

// copy the page from FLASH to RAM

for(i=0;i<PAGE_SIZE;i++)

Buffer[i] = *pFlashPage++;

// increment the counter

Buffer[0] += 1;

// now erase the page

page_erase(PAGE_START, 0xff, DATA_FLASH);

Result = 0;

// and write the modified contents back into flash

for(i=0;i<PAGE_SIZE;i++)

Result |= write_flash_chk (PAGE_START+i, Buffer[i],

DATA_FLASH);

// re−read the counter

pFlashPage = (char xdata *) PAGE_START;

printf(”flash write returned %d, Reset counter is now %d,

press any key\n”, (int) Result, (int)(*pFlashPage));

while(RI==0);

RI = 0;

}

}

Note:

Your program must use the boot ROM routines, such as write_flash_chk, in
order to modify flash data memory, if your program is itself executing from
flash memory. That is because the instructions are being fetched from flash
memory, and writing to flash memory simultaneously causes a conflict that
results in undesired program execution. The boot ROM routines must be
used to modify flash memory whenever your program itself resides on-chip
in flash memory.

Advertising