SM59R16 EEPROM 功能使用方法

SM59R16 EEPROM 功能使用方法
Application Note
SM59R16 EEPROM 功能使用方法
1
适用产品:SM59R16A2 / SM59R08A2
2
EEPROM 使用概述:
烧录次数限制:
SM59R16 使用 program flash 模拟为 Internal EEPROM,写入保证次数可逹 100K。
Page Erase 及 Program Byte 的动作说明:
Page Erase 是将 flash 的电位全部提升至”1”,Program Byte 是将 flash 的电位”high”拉为”low”。当程序执行一次
Program Byte,IC 内部硬件完整的步骤为:(1)read page(2)modify Byte(3)erase page(4)write page;写 N 个
byte,就必须经过 N 次(1~4)的步骤。
若少量次数的数据变动,可直接使用 EEPROM Program Byte 的方式。若大量的数据变动,为加快 Program Byte
完成的速度,可先将 (1)数据 page read 至 SRAM 中做修改 (2)将该 program flash 做 page erase (3)将 SRAM 资
料写回至 program flash。
A. 为什么第一次会较快?
因为当第一次使用时,flash 在 program 前已先被 erase 为 0xFF,当 IC 内部硬件判断该地址数据为 0xFF,在
program 时就会省略(3)Erase 的步骤。
B. 为什么第二次以后会变慢?
因为使用第二次以后,当 IC 内部硬件判断不为 0xFF,在 program 时就会做(3)Erase 的步骤。
Erase/Program/Read/Modify 测试速度:
System clock
(MHz)
25
24
22.1184
12
11.1592
Page Erase
(ms)
13.22
13.77
14.94
27.54
Program Byte
(us)
112.2
116.8
126.8
233.8
Read Byte
(us)
3.12
3.25
3.53
6.5
Modify Byte
(ms)
68.44
71.3
77.36
142.6
29.88
253.6
7.05
156.6
Note:
(1)Program Byte 即该位置原数据等于 0xFF (2)Modify Byte 即该位置原数据非 0xFF
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
1
Ver B 2009/02
SM59R16 EEPROM 功能使用方法
Application Note
应用说明:
如果使用 External ISP,烧录后 code flash 中的 data 如何保留?例如 Product ID、Key word 或 Menu setting …
应用方式如下:
1. 执行程序:read flash data,再将 data write to Xdata(SRAM)
2. 执行烧录:External ISP program (使用 OCD or MSM9055)
3. 执行重置:Reset MCU (不可断电)
4. 执行程序:read Xdata,再将 data write to flash,即可保存 flash 中的数据
256
512 (Byte)
SRAM-->code flash
3.4
6.8 ms
code flash-->SRAM
3
6 ms
test with external crystal 22.1184MHz
* 为保持 SRAM 中的数据正确,执行过程请勿中断电源。
* 此方法限制于内建 SRAM size,最大为 2KB。
3
EEPROM 相关的缓存器:
Mnemonic
PCON
PES
Description
Direct
Bit 7
Power Control
Program Memory
Page Erase
Control Register
87h
SMOD
A1h
EPE
Mnemonic: PCON
7
6
SMOD MDUF
5
-
Bit 6
Bit 5
Bit 4
EEPROM Function
MDUF
PMW
-
4
PMW
-
Bit 3
Bit 2
Bit 1
Bit 0
RESET
-
-
STOP
IDLE
00h
-
-
-
-
00h
-
3
-
2
-
1
STOP
3
-
2
-
1
-
Address: 87h
0
Reset
IDLE
00h
PMW = 1: R / W Flash Memory enable
PMW = 0:disable
Mnemonic: PES
7
6
EPE
5
-
4
-
Address: A1h
0
Reset
00h
EPE=1:执行抺除Page Erase (=512 bytes),完成后由硬件自动清
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
2
Ver B 2009/02
SM59R16 EEPROM 功能使用方法
Application Note
4
执行 EEPROM page erase 抺除程序,请参考如下:
//====================================================================
//This function will erase one page(512-Byte).
//SM59R16A2 64KB = 0~127 pages.
//SM59R08A2 32KB = 0~ 63 pages.
//====================================================================
void PMEE_PageErase(unsigned int Address)
{
unsigned char xdata *pAddr;
PCON |=0x10; // R / W Flash Memory enable
pAddr =Address;
PES =0x80;
// Page erase enable, after finish auto clear by hard
*pAddr=0xff; // Page erase command
PCON = PCON & 0xEF; // R / W Flash Memory disable
}
* EEPROM Erase 重要说明:
1.
page erase为一硬件设定动作,执行程序顺序请依照以上范例
2.
page erase enable与command之间,絶不可插入其它程序
3.
page erase enable后,必须在要抺除的flash page的第一个位置写入”0xFFh”,当作page erase
command,即可抺除,command address如下例表:
SM59R16/08 page Erase
Page
Memory address
0
0x0000~0x01FF
First byte address of page
(Command address)
0x0000
1
0x0200~0x03FF
0x0200
2
0x0400~0x05FF
0x0400
.
.
.
.
.
.
.
.
.
.
.
.
126
0xFC00~0xFDFF
0xFC00
127
0xFE00~0xFFFF
0xFE00
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
3
Ver B 2009/02
SM59R16 EEPROM 功能使用方法
Application Note
5
范例程序流程图(一):EEPROM 的应用流程图:
Entry SyncMOS
EEPROM function
<Step1> Execute:
EEPROM Erase
3rd. page
(0x0400~0x05FF)
<Step2> Execute:
EEPROM Byte Write
(PMEE_start~PMEE_END
=0x11)
< Step3. > Execute:
EEPROM Byte Read
(PMEE_start~PMEE_END)
ture
If = 0x11
fail
< Pass!! >
P2 give 0x55
P2 give 0x66
< Fail >
P2 give 0x77
P2 give 0x88
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
4
Ver B 2009/02
SM59R16 EEPROM 功能使用方法
Application Note
6
范例程序(一):EEPROM 范例程序
Description
Main program
//====================================================================
//
//
S Y N C M O S T E C H N O L O G Y
//
//====================================================================
#include "..\h\SM59R16A2.h"
#include "..\MISC\delay.h"
#define PMEE_start
#define PMEE_end
0X0400
0x0600
//====================================================================
//PES:Program Memory Page Erase Control Register
//When enable the EPE bit,the Page Erase(Each page include 512 bytes
//function can be executed by below Instructions?
//====================================================================
sfr PES = 0xA1;
//sbit EPE = PES^7;
//====================================================================
//This function will erase one page(512-Byte).
//SM59R16A2 64KB = 0~127 pages.
//SM59R08A2 32KB = 0~ 63 pages.
//====================================================================
void PMEE_PageErase(unsigned int Address)
{
unsigned char xdata *pAddr;
PCON |=0x10; // R / W Flash Memory enable
pAddr =Address;
PES =0x80;
// Page erase enable, after finish auto clear by hard
*pAddr=0xff; // Page erase command
PCON = PCON & 0xEF; // R / W Flash Memory disable
}
//====================================================================
//This function will write one byte to EEPROM.
//Adderss is from 0x0000~ 0xFFFF.
//====================================================================
void PMEE_ByteWrite(unsigned int Address, unsigned char Data)
{
unsigned char xdata *pAddr;
PCON
|= 0x10;
// R / W Flash Memory enable
pAddr
= Address;
// Set address
*pAddr = Data;
// Write data
PCON
= PCON & 0xEF; // R / W Flash Memory disable
}
//====================================================================
//This function will read one byte from EEPROM.
//Adderss is from 0x0000~ 0xFFFF.
//====================================================================
unsigned char PMEE_ByteRead(unsigned int Address)
{
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
5
Ver B
2009/02
SM59R16 EEPROM 功能使用方法
Application Note
unsigned char xdata *pAddr;
unsigned char temp;
PCON
|= 0x10;
// R / W Flash Memory enable
pAddr
= Address;
// Set address
temp
= (*pAddr);
// Read data
PCON
= PCON & 0xEF; // R / W Flash Memory disable
return(temp);
}
void main(void)
{
unsigned int i;
PMEE_PageErase(0x0400);
//Erase 3rd. page (0x0400~0x05FF)
for(i=PMEE_start; i<PMEE_end; i++) //EEPROM Write
{
PMEE_ByteWrite(i, 0x11);
}
while(1)
{
for(i=PMEE_start;i<PMEE_end;i++)
//EEPROM Read
{
if(PMEE_ByteRead(i) == 0x11)
//EEPROM Verify
{
P2 = 0x55; Delay1mSec(100);//Pass!!
P2 = 0x66; Delay1mSec(100);//Pass!!
}
else
{
P2 = 0x77; Delay1mSec(200);//Fail Warning!!
P2 = 0x88; Delay1mSec(200);//Fail Warning!!
}
}
}
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
6
Ver B
2009/02
SM59R16 EEPROM 功能使用方法
Application Note
7
范例程序流程图(二):EEPROM + SRAM 的应用流程图:
Entry SyncMOS
EEPROM function
< Step1. >
Triger_Int1()
1. Read EEPROM
2. Write to Xdata
< Step2. >
Execute External ISP
program
< Step3. >
Reset MCU
(don't power down!!)
< Step4. >
Entry main()
1. Read Xdata
2. Write to EEPROM
< Step5. >
User code....
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
7
Ver B
2009/02
SM59R16 EEPROM 功能使用方法
Application Note
8
范例程序(二):EEPROM + SRAM 使用的范例程序
Description
Main program
//====================================================================
//
//
S Y N C M O S T E C H N O L O G Y
//
//====================================================================
#include "..\h\SM59R16A2.h"
#include "..\h\SM59R16A2_extradef.h"
//#include "..\InternalEE\InternalEE.h"
#include "..\Interrupt\Interrupt.h"
#include "..\MISC\delay.h"
#define Expanded_start 0X0600
#define Expanded_end
0x0700
unsigned char xdata *Expanded_RAM;
unsigned char xdata *PMEE_RWpt;
//====================================================================
//This function will write one byte to eeprom.
//Adderss is from 0x0000~ 0xFFFF.
//====================================================================
void PMEE_ByteWrite(unsigned int Address, unsigned char Data)
{
//IEN0_EA = 0;
// Disable all interrupt
PCON
|= PCON_PROGMEM_WR;
// Enable eeprom write
PMEE_RWpt = Address;
// Set address
*PMEE_RWpt = Data;
// Write data
PCON
&= (~PCON_PROGMEM_WR); // Disable eeprom write
}
//====================================================================
//This function will read one byte from eeprom.
//Adderss is from 0x0000~ 0xFFFF.
//====================================================================
unsigned char PMEE_ByteRead(unsigned int Address)
{
unsigned char
temp;
//IEN0_EA = 0;
// Disable all interrupt
PCON
|= PCON_PROGMEM_WR; // Enable eeprom write
PMEE_RWpt = Address;
// Set address
temp
= (*PMEE_RWpt);
// Read data
PCON
&= (~PCON_PROGMEM_WR); // Disable eeprom write
return(temp);
}
void Expanded_RAM_Byte_Write(unsigned int addr, unsigned char dat)
{
Expanded_RAM = addr;
//set addr
*Expanded_RAM = dat;
//write Data
}
unsigned char Expanded_RAM_Byte_Read(unsigned int addr)
{
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
8
Ver B
2009/02
SM59R16 EEPROM 功能使用方法
Application Note
unsigned char dat;
Expanded_RAM = addr;
dat = *Expanded_RAM;
return dat;
//set addr
//read Data at
}
//====================================================================
// Read from eeprom, Write to Xdata. We want to keep Xdata
// so don't power down!!
//====================================================================
void Int1ISR(void) interrupt 2 using 0
{
unsigned int i;
unsigned char buff=0;
for(i=Expanded_start; i<Expanded_end; i++)
{
buff = PMEE_ByteRead(i);
//Read from eeprom
Expanded_RAM_Byte_Write( i , buff );//Write to Xdata
}
while(INT0IF)// Clear again to debounce.
{
INT1IF = false;
Delay10mSec(1);
}
}
void mcu_init(void)
{
//Initialize External INT
//Int0Init( EXINT0_EN, INT0_FALLEDGE );
Int1Init( EXINT1_EN, INT1_FALLEDGE );
}
void main(void)
{
unsigned int i;
unsigned char buff=0;
mcu_init();
// Read from Xdata, Write to eeprom
for(i=Expanded_start; i<Expanded_end; i++)
{
buff = Expanded_RAM_Byte_Read(i);
//Read from Xdata
PMEE_ByteWrite( i , buff );
//Write to eeprom
}
while(1)
{
//user code...
}
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A092
9
Ver B
2009/02