04.01.2014 Views

R8C/13 Group APPLICATION NOTE Flash Rewrite Using EW1 Mode

R8C/13 Group APPLICATION NOTE Flash Rewrite Using EW1 Mode

R8C/13 Group APPLICATION NOTE Flash Rewrite Using EW1 Mode

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>R8C</strong>/<strong>13</strong> <strong>Group</strong><br />

<strong>Flash</strong> <strong>Rewrite</strong> <strong>Using</strong> <strong>EW1</strong> <strong>Mode</strong> (Data "FFh" Search)<br />

/************************************************************************************<br />

Name: data_write<br />

Parameters: Record data address<br />

Returns: Program result<br />

Description: Record program<br />

************************************************************************************/<br />

unsigned char data_write( unsigned char *write_data ){<br />

unsigned char program_result = COMPLETE;<br />

int i; /* loop counter */<br />

/* If use interrupt then clear i flag... */<br />

/* asm("fclr i "); */<br />

/* flash control register set */<br />

fmr0 = 0x01;<br />

asm(""); /* Description for preventing the abbreviation by optimization */<br />

fmr0 = 0x03; /* CPU rewrite enable */<br />

fmr1 = 0x00;<br />

asm(""); /* Description for preventing the abbreviation by optimization */<br />

fmr1 = 0x02; /* <strong>EW1</strong> mode */<br />

for( i = 0; i < RECORD_SIZE; i++ ){<br />

write_addr[i] = 0x40;<br />

write_addr[i] = write_data[i];<br />

while( fmr00 != 1 ); /* Ready check */<br />

/* Program status check */<br />

if( fmr06 == 1 ){<br />

/* Program error */<br />

*write_addr = 0x50; /* Clear stutus register */<br />

program_result = PROGRAM_ERR;<br />

break;<br />

}<br />

}<br />

/* flash control register reset */<br />

fmr0 = 0x01; /* CPU rewrite disable */<br />

/* If use interrupt then set i flag... */<br />

/* asm("fset i "); */<br />

}<br />

return program_result;<br />

REJ05B0444-0110Z/Rev.1.10 August 2004 Page 22 of 25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!