U17379EJ3V0AN00
U17379EJ3V0AN00
On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology
Corporation, and Renesas Electronics Corporation took over all the business of both
companies. Therefore, although the old company name remains in this document, it is a valid
Renesas Electronics document. We appreciate your understanding.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation and also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
Application Note
78K0S/Kx1+
8-Bit Single-Chip Microcontrollers
TM
EEPROM Emulation
μPD78F9200 μPD78F9500
μPD78F9201 μPD78F9501
μPD78F9202 μPD78F9502
μPD78F9210 μPD78F9510
μPD78F9211 μPD78F9511
μPD78F9212 μPD78F9512
μPD78F9221
μPD78F9222
μPD78F9224
μPD78F9232
μPD78F9234
Document No. U17379EJ3V0AN00 (3rd edition)
Date Published September 2009 NS
2005
Printed in Japan
[MEMO]
(1) VOLTAGE APPLICATION WAVEFORM AT INPUT PIN: Waveform distortion due to input noise or a reflected
wave may cause malfunction. If the input of the CMOS device stays in the area between VIL (MAX) and VIH
(MIN) due to noise, etc., the device may malfunction. Take care to prevent chattering noise from entering the
device when the input level is fixed, and also in the transition period when the input level passes through the
area between VIL (MAX) and VIH (MIN).
(2) HANDLING OF UNUSED INPUT PINS: Unconnected CMOS device inputs can be cause of malfunction. If
an input pin is unconnected, it is possible that an internal input level may be generated due to noise, etc.,
causing malfunction. CMOS devices behave differently than Bipolar or NMOS devices. Input levels of CMOS
devices must be fixed high or low by using pull-up or pull-down circuitry. Each unused pin should be
connected to VDD or GND via a resistor if there is a possibility that it will be an output pin. All handling
related to unused pins must be judged separately for each device and according to related specifications
governing the device.
(3) PRECAUTION AGAINST ESD: A strong electric field, when exposed to a MOS device, can cause destruction
of the gate oxide and ultimately degrade the device operation. Steps must be taken to stop generation of
static electricity as much as possible, and quickly dissipate it when it has occurred. Environmental control
must be adequate. When it is dry, a humidifier should be used. It is recommended to avoid using insulators
that easily build up static electricity. Semiconductor devices must be stored and transported in an anti-static
container, static shielding bag or conductive material. All test and measurement tools including work benches
and floors should be grounded. The operator should be grounded using a wrist strap. Semiconductor
devices must not be touched with bare hands. Similar precautions need to be taken for PW boards with
mounted semiconductor devices.
(4) STATUS BEFORE INITIALIZATION: Power-on does not necessarily define the initial status of a MOS device.
Immediately after the power source is turned ON, devices with reset functions have not yet been initialized.
Hence, power-on does not guarantee output pin levels, I/O settings or contents of registers. A device is not
initialized until the reset signal is received. A reset operation must be executed immediately after power-on
for devices with reset functions.
(5) POWER ON/OFF SEQUENCE: In the case of a device that uses different power supplies for the internal
operation and external interface, as a rule, switch on the external power supply after switching on the internal
power supply. When switching the power supply off, as a rule, switch off the external power supply and then
the internal power supply. Use of the reverse power on/off sequences may result in the application of an
overvoltage to the internal elements of the device, causing malfunction and degradation of internal elements
due to the passage of an abnormal current. The correct power on/off sequence must be judged separately for
each device and according to related specifications governing the device.
(6) INPUT OF SIGNAL DURING POWER OFF STATE : Do not input signals or an I/O pull-up power supply while
the device is not powered. The current injection that results from input of such a signal or I/O pull-up power
supply may cause malfunction and the abnormal current that passes in the device at this time may cause
degradation of internal elements. Input of signals during the power off state must be judged separately for
each device and according to related specifications governing the device.
Caution: This product uses SuperFlash® technology licensed from Silicon Storage Technology, Inc.
• The information in this document is current as of September, 2009. The information is subject to change without notice. For
actual design-in, refer to the latest publications of NEC Electronics data sheets or data books, etc., for the most up-to-date
specifications of NEC Electronics products. Not all products and/or types are available in every country. Please check with
an NEC Electronics sales representative for availability and additional information.
• No part of this document may be copied or reproduced in any form or by any means without the prior written consent of NEC
Electronics. NEC Electronics assumes no responsibility for any errors that may appear in this document.
• NEC Electronics does not assume any liability for infringement of patents, copyrights or other intellectual property rights of
third parties by or arising from the use of NEC Electronics products listed in this document or any other liability arising from the
use of such products. No license, express, implied or otherwise, is granted under any patents, copyrights or other intellectual
property rights of NEC Electronics or others.
• Descriptions of circuits, software and other related information in this document are provided for illustrative purposes in
semiconductor product operation and application examples. The incorporation of these circuits, software and information in
the design of a customer's equipment shall be done under the full responsibility of the customer. NEC Electronics assumes
no responsibility for any losses incurred by customers or third parties arising from the use of these circuits, software and
information.
• While NEC Electronics endeavors to enhance the quality, reliability and safety of NEC Electronics products, customers agree
and acknowledge that the possibility of defects thereof cannot be eliminated entirely. To minimize risks of damage to property
or injury (including death) to persons arising from defects in NEC Electronics products, customers must incorporate sufficient
safety measures in their design, such as redundancy, fire-containment and anti-failure features.
• NEC Electronics products are classified into the following three quality grades: "Standard", "Special" and "Specific". The
"Specific" quality grade applies only to NEC Electronics products developed based on a customer-designated "quality
assurance program" for a specific application. The recommended applications of an NEC Electronics product depend on its
quality grade, as indicated below. Customers must check the quality grade of each NEC Electronics product before using it in
a particular application.
"Standard": Computers, office equipment, communications equipment, test and measurement equipment, audio and visual
equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots.
"Special": Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster systems, anti-
crime systems, safety equipment and medical equipment (not specifically designed for life support).
"Specific": Aircraft, aerospace equipment, submersible repeaters, nuclear reactor control systems, life support systems and
medical equipment for life support, etc.
The quality grade of NEC Electronics products is "Standard" unless otherwise expressly specified in NEC Electronics data
sheets or data books, etc. If customers wish to use NEC Electronics products in applications not intended by NEC
Electronics, they must contact an NEC Electronics sales representative in advance to determine NEC Electronics' willingness
to support a given application.
(Note 1) "NEC Electronics" as used in this statement means NEC Electronics Corporation and also includes its majority-
owned subsidiaries.
(Note 2) "NEC Electronics products" means any product developed or manufactured by or for NEC Electronics (as defined
above).
(M8E0909)
Target readers This application note is intended for users who understand the functions of the
78K0S/Kx1+ with on-chip flash memory and who will use this product to design
application systems.
Purpose The purpose of this application note is to inform users concerning the use of the
78K0S/Kx1+ flash memory self programming functions, and the method for storing data
(writing constant data using application) during EEPROM emulation of flash memory.
How to read this manual It is assumed that the reader of this manual has general knowledge in the fields of
electrical engineering, logic circuits, and microcontrollers.
To learn more about the 78K0S/Kx1+’s hardware functions:
→ See the user’s manual of each 78K0S/Kx1+ product.
To learn more about the 78K0S/Kx1+’s flash memory self programming functions:
→ See the flash memory chapter in the user’s manual for each 78K0S/Kx1+ product.
To gain a general understanding of functions:
→ Read this manual in the order of the CONTENTS. The mark “<R>” shows major
revised points. The revised points can be easily searched by copying an “<R>” in
the PDF file and specifying it in the “Find what:” field.
Convention Data significance: Higher digits on the left and lower digits on the right
Active low representation: xxx (overscore over pin or signal name)
Note: Footnote for item marked with Note in the text
Caution: Information requiring particular attention
Remark: Supplementary information
Numeral representation: Binary..................xxxx or xxxxB
Decimal ...............xxxx
Hexadecimal .......xxxxH
Related Documents The related documents indicated in this publication may include preliminary versions.
However, preliminary versions are not marked as such.
The 78K0S/Kx1+ enables writing from an application program to flash memory (i.e., “flash memory self
programming”).
This application note describes how to store (reading or writing as with EEPROM) any data to the flash memory by
using the self programming function.
Remark For a more detailed description of flash memory self programming, see the flash memory chapter in the
user’s manual for each 78K0S/Kx1+ products.
The area that is used for erasing, blank checks, and verification during flash memory control operations is specified
in block units. The block numbers that can be specified are listed in Figure 1-1.
Caution Any areas other than the product’s flash memory area cannot be accessed.
EEPROM emulation is a function that is used to use a portion of the flash memory as rewritable data ROM, by
using the self programming function of the flash memory. The sample program can be used in combination with a
user program to perform read or write processing, as with EEPROM.
Note that the data length and number of rewrites is restricted, because the internal flash memory can only be
rewritten a limited number of times. Next, the basic specifications of the sample program and how to calculate the
number of rewrites is described.
Basic specifications of the sample program and how to calculate the number of rewrites
↑ ↑
Any data Indicates the write status. Used for data search.
Remark The data size can be set, starting from 1 byte. The upper size limit depends on the RAM size.
Data size
Valid or invalid flag (see 2.1.3)
Memory size of one block
In the sample program, data is handled in 2-byte units, and 84 rewrites can be performed per block (256 bytes), in
combination with a delimiter (1 byte) that indicates the end of data. Furthermore, since an area of at least two
<R> consecutive blocks is required to avoid losses caused, for example, by an unexpected power supply voltage drop, a
total of 168 rewrites can be performed when two blocks are used. In addition, since a block can be erased up to
1,000 times in the sample program, data can be rewritten up to 168,000 times when two blocks are used.
At least two consecutive blocks must be secured to allocate the flash memory for storing data. These blocks can
be set freely by the user.
Figure 2-1 shows a memory map and data structure example in which the program size is 3.5 KB and blocks 14
and 15 are set to be used for EEPROM emulation.
1 byte 1 byte
Can support up to
3.5 KB total
Block 4
Block 3
Block 2
Block 1
Block 0
0000H
Remark Data structure in Figure 2-1 shows the example when used the sample program.
(1) Data
Any value from 00H to FFH can be set. The size can be set, starting from 1 byte. Note, however, that, the
larger the size, the more the number of rewrites will decrease.
(2) Delimiter
The delimiter’s value is fixed as 00H. Delimiters are written to enable detection of unsuccessful data writing,
such as in cases where power interruptions or other problems occurred during a data write operation.
Whether data writing has completed normally is judged by writing a delimiter area last. If a delimiter (00H)
cannot be read correctly, it is likely that a problem will occur when writing data, so the corresponding data is
not used.
If a search finds an abnormal delimiter in the latest data, the data written before that data, having a normal
delimiter, is read as the latest data.
How to read
<1> Since data a has a different data number, the operation goes to the next data.
<2> Since data b has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, and the operation goes to the next data.
<3> Since data c has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, and the operation goes to the next data.
<4> Check whether the block has been erased to the end.
<5> The read value therefore becomes the latest stored data (data c).
The following describes the flow of operations when a problem such as a power interruption occurs while
storing data (in this example, the blocks specified for EEPROM emulation are blocks 14 and 15).
(Status 3) Power interruption occurs while data number 1 (for data values 22H, 33H) is being written and
delimiter cannot be written correctly (value other than 00H is written)
Block 14 +0 +1 +2
Valid flag 00H 0E00H
Invalid flag FFH 0E01H
Data 11H 22H 00H 0E02H
Data 22H 33H 01H 0E06H
: FFH 0E0AH
How to read
<1> Since data a has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, the operation goes to the next data.
<2> Since data b has a matching data number, its delimiter is checked, and since the delimiter value is 01H
(abnormal), the operation goes to the next data.
<3> Check whether the block has been erased to the end.
<4> The read value therefore becomes the latest stored data (data a).
Be sure to meet all of the conditions listed in Table 2-1 before executing the EEPROM emulation program.
Item Description
Secure stack area During EEPROM emulation program operations, the stack used by the user program is
(Assembly language: 22 bytes) inherited and used. In addition, the stack area described on the left starting from the stack
address at the start of EEPROM emulation program execution is required. See 3.2 Resources
Used by EEPROM Emulation Program for further description of this stack.
EEPROM emulation program The area must be secured as RAM dedicated to EEPROM emulation, where read and write
RAM data are stored temporarily. Secure the area described on the left in the internal high-speed
(Assembly language: 8 bytes) RAM as a data buffer.
Operation of watchdog timer Since no instruction can be executed while flash memory control processing is being
(WDT) performed during execution of the EEPROM emulation program, flash memory control
processing clears the WDT counter. At this time, set the overflow time to 10 ms or longer so
that no overflow occurs in WDT.
Prohibit reset Do not reset this microcontroller during EEPROM emulation program operations. When a reset
occurs, any data in the flash memory being accessed becomes undefined.
Prohibit power cut-off or Be sure to apply a stable voltage to the microcontroller during EEPROM emulation program
interruption operations. When a power cut-off or interruption occurs, any data in the flash memory being
accessed becomes undefined.
Cautions 1. All interrupts are disabled during write processing of the EEPROM emulation program. After
completion of EEPROM emulation program write processing, the interrupt mask status
returns to the status before the EEPROM emulation program write processing, and interrupts
are enabled.
<R> 2. When using the on-chip debug function, do not allocate areas such as the EEPROM
emulation data area to the area where the monitor program for debugging is allocated.
Remark For details on the watchdog timer operation and prohibitions on power cut-off or interruption, refer to
Cautions on self programming function in the flash memory chapter in the user’s manual for each
78K0S/Kx1+ product.
<R> For details on the on-chip debug function, refer to the on-chip debug function chapter in the user’s
manual for each 78K0S/Kx1+ product.
This is an application program that uses the self programming function of the flash memory in order to use the
flash memory as EEPROM memory for storing data, etc.
The resources used by this program are listed in Table 3-2 below.
Resource Description
EEPROM emulation described in this chapter uses at least two blocks of flash memory. Two bytes of data can be
referred and updated to flash memory during EEPROM emulation.
When this EEPROM emulation program is embedded in the user application, the conditions are met (see 2.2
EEPROM Emulation Program Execution Conditions), and the specified program is executed, EEPROM emulation
can be performed.
The following explains how the “fixed-length data method, assembly language” program can be used to perform
EEPROM emulations.
Example 1. When using two blocks (blocks 14 and 15) as EEPROM blocks
EEPROM_BLOCK EQU (14)
For main.asm (assembler version), use the variable EEPROM_DATA defined below.
EEPROM_DATA: DS 2 ; Data
EEPROM_DELIMITER: DS 1 ; Delimiter
For main.c (C language version), use the structure eeprom_data defined below.
Struct eeprom_data{
};
(1) EEPROM read processing (__eeprom_read): Reads from the EEPROM area the data of the set size.
(2) EEPROM write processing (EEPROMWrite): Writes to the EEPROM area the data of the set size.
Table 3-11. Mode Transition Processing (from Self Programming Mode to Normal Mode)
Table 3-12. Mode Transition Processing (from Normal Mode to Self Programming Mode)
[Overview]
The data defined with the structure is read from specified storage address.
__eeprom_read
No
Block found?
Yes
Searches for latest data
(EEPROMDataSearch)
Data found? No
Yes
Store latest data
to specified address
CY = 0 CY = 1
(read successful) (read failure)
RET
[Overview]
The data of the specified number is written to a valid block from the storage address.
__eeprom_write
Yes
Block found?
No
Specify first valid block Search writable area
(EEPROMBlockInit) (EEPROMWriteTopSearch)
Block change No
successful?
A
Yes
Write successful? Yes
A No
Release flash mode Release flash mode
(SelfFlashModeOff) (SelfFlashModeOff)
CY = 1 CY = 0
(write failure ) (write successful )
RET
[Overview]
The currently used blocks of the flash memory that is allocated as EEPROM is searched.
EEPROMUseBlockSearch
Yes
Valid block checked?
No
Store valid block number
Move to next block
to CurentB_No
No
All set blocks completed?
Yes
CY = 1 CY = 0
(search failure) (search successful)
RET
[Overview]
If there are no valid blocks among the blocks specified for EEPROM, the first specified block is set as valid.
EEPROMBlockInit
No
Erased?
Yes
Set block as valid
(Setvalid)
No
Valid flag set?
Yes
CY = 0 CY = 1
(initialize successful ) (initialize failure)
Initialize completion
[Overview]
If the currently used blocks are full of data, this function searches for the next block to be used and copies data to new
block.
EEPROMUseBlockChange
No
Erased?
Yes
Write next block's data
Set start address
No
Write successful?
Yes
Set valid flag to new block
(Setvalid)
No
Is valid flag normal?
Yes
Set invalid flag to old block
(Setinvalid)
No
Is invalid flag normal?
Yes
CY = 0 CY = 1
(update successful) (update failure)
RET
Figure 3-6. Flowchart of EEPROM Use Block Data Write Top Search Processing
[Overview]
Searches for specified block’s write area.
Completes normally only if the data area fits within the block at 0xFFH.
EEPROMWriteTopSearch
Delimiter≠ FFH
Delimiter checked?
Delimiter = FFH
Check data erasure of
write area
No
Is data FF?
Yes
CY = 0
(Search successful)
RET
No
End of block?
Yes
CY = 1
(Search failure)
RET
[Overview]
Reads the storage address of the latest data.
EEPROMDataSearch
No
Delimiter ≠ 00H
Delimiter checked?
Delimiter = 00H
Copy address to DE register
(return value)
No
Search successful?
Yes
CY = 0 CY = 1
(Search successful) (Search failure)
RET
User access processings EEPROM emulation processings Flash memory control processings
__eerom_read EEPROMUseBlockSearch
EEPROMDataSearch
__eeprom_write SelfFlashModeOn
SelfFlashModeOff
EEPROMUseBlockSearch
FlashBlockErase
FlashEEPROMWrite
EEPROMWriteTopSearch
FlashBlockErase
FlashEEPROMWrite
SetValid
SetInvalid
EEPROMDataSearch
FlashEEPROMWrite
EEPROM emulation is a function that is used to use a portion of the flash memory as rewritable data ROM, by
using the self programming function of the flash memory. The sample program can be used in combination with a
user program to perform read or write processing, as with EEPROM.
Note that the data length and number of rewrites is restricted, because the internal flash memory can only be
rewritten a limited number of times. Next, the basic specifications of the sample program and how to calculate the
number of rewrites is described.
Basic specifications of the sample program and how to calculate the number of rewrites
↑
Number distinguishing the data to be saved (Two types of data numbers are used in the sample program.)
Remark The data size can be set, starting from 1 byte. The upper size limit depends on the RAM size.
In the sample program, data is handled in 2-byte units, and 62 rewrites can be performed per block (256 bytes), in
combination with a delimiter (1 byte) that indicates the end of data. Furthermore, since an area of at least two
<R> consecutive blocks is required to avoid losses caused, for example, by an unexpected power supply voltage drop, a
total of 124 rewrites can be performed when two blocks are used. In addition, since a block can be erased up to
1,000 times in the sample program, data can be rewritten up to 124,000 times when two blocks are used.
If, however, the total number of bytes of all EEPROM storage data (data + delimiter) types is not sufficiently large
with respect to the storage block size (i.e., the total number of bytes of the data is larger than half the block size),
EEPROM emulation may not function correctly. In particular, the transfer of data between blocks may occur
frequently and the number of data rewrites may significantly decrease.
At least two consecutive blocks must be secured to allocate the flash memory for storing data. These blocks can
be set freely by the user.
Figure 4-1 shows a memory map and data structure example in which the user program size is 3.5 KB and blocks
14 and 15 are set to be used for EEPROM emulation.
1 byte 1 byte
Can support up to
3.5 KB total
Block 4
Block 3
Block 2
Block 1
Block 0
0000H
Remark Data structure in Figure 2-1 shows the example when used the sample program.
Remark Two types of data numbers are used in the sample program.
(2) Data
00H to FFH can be set by any value that is to be stored. The data size can be set, starting from 1 byte, but
the upper size limit depends on the RAM size that can be used. Note, however, that, the larger the size, the
more the number of rewrites will decrease. It is specified as 2 bytes (the data length (LENG) is defined as 4)
in the sample program.
(3) Delimiter
The delimiter’s value is fixed as 00H. Delimiters are written to enable detection of unsuccessful data writing,
such as in cases where power interruptions or other problems occurred during a data write operation.
Whether data writing has completed normally is judged by writing a delimiter area last. If a delimiter (00H)
cannot be read correctly, it is likely that a problem will occur when writing data, so the corresponding data is
not used.
If a search finds an abnormal delimiter in the latest data, the data written before that data (followed by the data
closest to the next end point), having a normal delimiter, is read as the latest data.
(Status 2) Data number 1 (for data values 11H and 22H) is written.
Block 14 +0 +1 +2 +3
Valid flag 00H 0E00H
Invalid flag FFH 0E01H
Data 01H 11H 22H 00H 0E02H
: FFH 0E06H
<1> Since data a has a different data number, the operation goes to the next data.
<2> Since data b has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, and the operation goes to the next data.
<3> Since data c has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, and the operation goes to the next data.
<4> The data number for data d is FFH (end point), so the read operation is terminated.
<5> The read value therefore becomes the latest stored data (data c).
The following describes the flow of operations when a problem such as a power interruption occurs while
storing data (in this example, the blocks specified for EEPROM emulation are blocks 14 and 15).
(Status 3) Power interruption occurs while data number 1 (for data values 22H, 33H) is being written and
delimiter cannot be written correctly (value other than 00H is written)
Block 14 +0 +1 +2 +3
Valid flag 00H 0E00H
Invalid flag FFH 0E01H
Data 01H 11H 22H 00H 0E02H
Data 01H 22H 33H 01H 0E06H
: FFH 0E0AH
How to read
<1> Since data a has a matching data number, its delimiter is checked, and since the delimiter value is 00H
(normal), data of 2 bytes is stored as the latest data, the operation goes to the next data.
<2> Since data b has a matching data number, its delimiter is checked, and since the delimiter value is 01H
(abnormal), the operation goes to the next data.
<3> The data number for data c is FFH (end point), so the read operation is terminated.
<4> The read value therefore becomes the latest stored data (data a).
(Status 5) The latest data to be updated is written after the latest data whose data number has not been updated is
transferred to block n + 1.
Block n Block n + 1
Valid flag 00H Valid flag FFH
Invalid flag FFH Invalid flag FFH
Data Data Data Data
: : : :
Data Data Data FFH
(Status 10) The latest data to be updated is written after the latest data whose data number has not been updated
is transferred to block n.
Block n Block n + 1
Valid flag FFH Valid flag 00H
Invalid flag FFH Invalid flag FFH
Data Data Data Data
: : : :
Data FFH Data Data
Be sure to meet all of the conditions listed in Table 4-1 before executing the EEPROM emulation program.
Item Description
Secure stack area During EEPROM emulation program operations, the stack used by the user program is
(Assembly language: 22 bytes) inherited and used. In addition, the stack area described on the left starting from the stack
address at the start of EEPROM emulation program execution is required. See 5.2 Resources
Used by EEPROM Emulation Program for further description of this stack.
EEPROM emulation program The area must be secured as RAM dedicated to EEPROM emulation, where read and write
RAM data are stored temporarily. Secure the area described on the left in the internal high-speed
(Assembly language: 11 bytes) RAM as a data buffer. In addition to the RAM for the program described on the left, only the
stack area is used by the EEPROM emulation program.
Operation of watchdog timer Since no instruction can be executed while flash memory control processing is being
(WDT) performed during execution of the EEPROM emulation program, flash memory control
processing clears the WDT counter. At this time, set the overflow time to 10 ms or longer so
that no overflow occurs in WDT.
Prohibit reset Do not reset this microcontroller during EEPROM emulation program operations. When a reset
occurs, any data in the flash memory being accessed becomes undefined.
Prohibit power cut-off or Be sure to apply a stable voltage to the microcontroller during EEPROM emulation program
interruption operations. When a power cut-off or interruption occurs, any data in the flash memory being
accessed becomes undefined.
Cautions 1. All interrupts are disabled during write processing of the EEPROM emulation program. After
completion of EEPROM emulation program write processing, the interrupt mask status
returns to the status before the EEPROM emulation program write processing, and interrupts
are enabled.
<R> 2. When using the on-chip debug function, do not allocate areas such as the EEPROM
emulation data area to the area where the monitor program for debugging is allocated.
Remark For details on the watchdog timer operation and prohibitions on power cut-off or interruption, refer to
Cautions on self programming function in the flash memory chapter in the user’s manual for each
78K0S/Kx1+ product.
<R> For details on the on-chip debug function, refer to the on-chip debug function chapter in the user’s
manual for each 78K0S/Kx1+ product.
This is an application program that uses the self programming function of the flash memory in order to use the
flash memory as EEPROM memory for storing data, etc.
The resources used by this program are listed in Table 5-2 below.
Resource Description
EEPROM emulation described in this chapter uses at least two blocks of flash memory. Two bytes of data can be
referred and updated to flash memory during EEPROM emulation.
When this EEPROM emulation program is embedded in the user application, the conditions are met (see 4.2
EEPROM Emulation Program Execution Conditions), and the specified program is executed, EEPROM emulation
can be performed.
The following explains how the “fixed-length multiple-data method, assembly language” program can be used to
perform EEPROM emulations.
(1) The block numbers and the number of blocks used as EEPROM
Specify the block numbers of blocks to be used for EEPROM emulation. The set blocks must be consecutive
for more than 2 blocks. Set the blocks so that they do not overlap the user program area.
The number of EEPROM rewrite cycles can be increased by increasing the number of blocks used as
EEPROM. Regardless of the amount of data used for EEPROM emulation, we recommend that any area that
is not being used as a program area should be set for use in EEPROM emulation.
Example 1. When using two blocks (blocks 14 and 15) as EEPROM blocks
EEPROM_BLOCK EQU (14)
LENG EQU (4) ; Data length (size including data number and delimiter
(2 bytes, total))
To set it under different conditions, set it larger than the block erasure time divided by 8.5 ms. The time for
one erase is 8.5 ms.
For main.asm (assembler version), use the variable EEPROM_DATA defined below.
EEPROM_DO: DS 1 ; Data number
EEPROM_DATA: DS 2 ; Data
EEPROM_DELIMITER: DS 1 ; Delimiter
For main.c (C language version), use the structure eeprom_data defined below.
Struct eeprom_data{
};
(1) EEPROM read processing (__eeprom_read): Reads from the EEPROM area the data of the set size.
the data number is within the set range. An error will occur if data with the specified number is not written
even once.
(2) EEPROM write processing (__eeprom_write): Writes to the EEPROM area the data of the set size.
Table 5-12. Mode Transition Processing (from Self Programming Mode to Normal Mode)
Table 5-13. Mode Transition Processing (from Normal Mode to Self Programming Mode)
[Overview]
The data defined with the structure is read from specified storage address.
__eeprom_read
No
Block found?
Yes
Searches for latest data
(EEPROMDataSearch)
Data found? No
Yes
Store latest data to specified
data area of structure
CY = 0 CY = 1
(read successful) (read failure)
RET
[Overview]
The data of the specified number is written to a valid block from the storage address.
__eeprom_write
Yes
Block found?
No
Specify first valid block Search writable area
(EEPROMBlockInit) (EEPROMWriteTopSearch)
Block change No
successful?
A
Yes
Write successful? Yes
A No
Release flash mode Release flash mode
(SelfFlashModeOff) (SelfFlashModeOff)
CY = 1 CY = 0
(write failure) (write successful)
RET
[Overview]
The currently used blocks of the flash memory that is allocated as EEPROM is searched.
EEPROMUseBlockSearch
Yes
Valid block checked?
No
Store valid block number
Move to next block
to CurentB_No
No
All set blocks completed?
Yes
CY = 1 CY = 0
(search failure) (search successful)
RET
[Overview]
If there are no valid blocks among the blocks specified for EEPROM, the first specified block is set as valid.
EEPROMBlockInit
No
Erased?
Yes
Set block as valid
(Setvalid)
No
Valid flag set?
Yes
CY = 0 CY = 1
(initialize successful) (initialize failure)
Initialize completion
[Overview]
If the currently used blocks are full of data, this function searches for the next block to be used and copies data to new
block.
EEPROMUseBlockChange
No
Erased?
Yes
Write next block's data
Set start address
1
Initialize data number
4
Data number Yes
to be written?
No
Search latest data
(EEPROMDataSearch)
No
2 Latest data detected?
Yes
No
Write successful?
2 Yes
Yes
All data complete?
No
4
No
Is valid flag normal?
Yes
Set invalid flag to old block
(Setinvalid)
No
Is invalid flag normal?
Yes
CY = 0 CY = 1
(update successful) (update failure)
RET
Figure 5-6. Flowchart of EEPROM Use Block Data Write Top Search Processing
[Overview]
Searches for specified block’s write area.
Completes normally only if the data area fits within the block at 0xFFH.
EEPROMWriteTopSearch
No
Is data FF?
Yes
CY = 0
(Search successful)
RET
No
End of block?
Yes
CY = 1
(Search failure)
RET
[Overview]
Reads the storage address of the latest data.
EEPROMDataSearch
Yes
Data number matched?
No
Delimiter ≠ 00H
Delimiter checked?
Delimiter = 00H
Copy address to DE register
(return value)
Yes
Is data FF?
No
No
Search successful ?
Yes
CY = 0 CY = 1
(Search successful) (Search failure)
RET
User access processings EEPROM emulation processings Flash memory control processings
__eerprom_read getpara
EEPROMUseBlockSearch
EEPROMDataSearch
__eeprom_write getpara
SelfFlashModeOn
SelfFlashModeOff
EEPROMUseBlockSearch
FlashBlockErase
FlashEEPROMWrite
EEPROMWriteTopSearch
FlashBlockErase
FlashEEPROMWrite
SetValid
EEPROMDataSearch SetInvalid
FlashEEPROMWrite
Page Description
p. 66 in Deletion of APPENDIX A SAMPLE PROGRAM LIST (FIXED-LENGTH SINGLE-DATA METHOD) from old
old edition edition
p. 84 in Deletion of APPENDIX B SAMPLE PROGRAM LIST (FIXED-LENGTH MULTIPLE-DATA METHOD) from old
old edition edition
CHAPTER 2 EEPROM EMULATION FUNCTION (FIXED-LENGTH SINGLE-DATA METHOD)
pp. 9, 10 Modification of the number of erasures of one block, and the maximum number of rewrites in 2.1 Main
Specifications for EEPROM Emulation
p. 17 Addition of caution 2 to, and modification of Remark in Table 2-1 Conditions for EEPROM Emulation
Operations
p. 17 Addition of 2.3 How to Get the Sample Program
CHAPTER 3 EEPROM EMULATION PROGRAM (FIXED-LENGTH SINGLE-DATA METHOD, ASSEMBLYLANGUAGE)
p. 18 Modification of Table 3-2 Resources
p. 19 Modification of 3.3.1 (3) Number of erase retrials
pp. 26, 28 Modification of Table 3-10 Block Erase and Table 3-17 EEPROM Data Write Processing
CHAPTER 4 EEPROM EMULATION FUNCTION (FIXED-LENGTH MULTIPLE-DATA METHOD)
p. 37 Modification of the number of erasures of one block, and the maximum number of rewrites in 4.1 Main
Specifications for EEPROM Emulation
p. 45 Addition of caution 2 to, and modification of Remark in Table 4-1 Conditions for EEPROM Emulation
Operations
p. 45 Addition of 4.3 How to Get the Sample Program
CHAPTER 5 EEPROM EMULATION PROGRAM (FIXED-LENGTH MULTIPLE-DATA METHOD, ASSEMBLY LANGUAGE)
p. 46 Modification of Table 5-2 Resources
p. 47 Modification of 5.3.1 (3) Number of erase retrials
pp. 54, 56 Modification of Table 5-11 Block Erase and Table 5-18 EEPROM Data Write Processing
APPENDIX A REVISION HISTORY
p. 67 Addition of A.2 Revision History of Preceding Editions
Here is the revision history of the preceding editions. Chapter indicates the chapter of each edition.