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 />

5. Programming Code<br />

The sample program is described below.<br />

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

* *<br />

* File Name : main.c *<br />

* Contents : Main program of the <strong>EW1</strong> mode sample program <strong>R8C</strong>/<strong>13</strong> <strong>Group</strong> *<br />

* Copyright(C)2004, Renesas Technology Corp. *<br />

* Copyright(C)2004, Renesas Solutions Corp. *<br />

* All rights reserved. *<br />

* Version : 1.10 *<br />

* note : 0.01 : First version *<br />

* : 1.10(2004.08.23): Comment is revised *<br />

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

#include "sfr_r8<strong>13</strong>.h"<br />

/* Definition of const data */<br />

#define BLOCK_A ((unsigned char *)0x2000) /* BLOCK A first address */<br />

#define BLOCK_A_END ((unsigned char *)0x27ff) /* BLOCK A last address */<br />

#define BLOCK_B ((unsigned char *)0x2800) /* BLOCK B first address */<br />

#define BLOCK_B_END ((unsigned char *)0x2fff) /* BLOCK B last address */<br />

#define RECORD_PER_BLOCK 16 /* Record number per 1 block */<br />

#define RECORD_SIZE 128 /* Record size */<br />

#define BLOCK_A_SELECT 0 /* Use BLOCK A */<br />

#define BLOCK_B_SELECT 1 /* Use BLOCK B */<br />

#define COMPLETE 0x00 /* FLASH write/erase complete */<br />

#define PROGRAM_ERR 0x01 /* FLASH data write error */<br />

#define ERASE_ERR 0x02 /* FLASH erase error */<br />

/* Definition of RAM area */<br />

unsigned char *write_addr; /* Write address */<br />

unsigned char block_select; /* Block select flag */<br />

/* Declaration of function prototype */<br />

void write_address_init(void);<br />

unsigned char flash_write(unsigned char *data);<br />

unsigned char block_erase(unsigned char *ers_addr);<br />

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

void make_data(unsigned char *write_data);<br />

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

Name: main<br />

Parameters: None<br />

Returns: None<br />

Description: User main<br />

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

void main(void){<br />

static unsigned char write_data[RECORD_SIZE]; /* wirte data */<br />

unsigned char result;<br />

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

-Change on-chip oscillator clock to Main clock -<br />

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

prc0 = 1; /* Protect off */<br />

cm<strong>13</strong> = 1; /* Xin Xout */<br />

cm15 = 1; /* XCIN-XCOUT drive capacity select bit : HIGH */<br />

cm05 = 0; /* Xin on */<br />

cm16 = 0; /* Main clock = No division mode */<br />

cm17 = 0;<br />

cm06 = 0; /* CM16 and CM17 enable */<br />

asm("nop"); /* Waiting for stable of oscillation */<br />

asm("nop");<br />

asm("nop");<br />

asm("nop");<br />

ocd2 = 0; /* Main clock change */<br />

prc0 = 0; /* Protect on */<br />

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

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

Saved successfully!

Ooh no, something went wrong!