给你个例程看看
#include <iostm8s103f3.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
#define MASS_KEY1 0xAE
#define MASS_KEY2 0x56
#define EEP_BASE 0x4000
void delay_ms(uchar ms)
{
uchar i,j;
while(ms--)
{
for(i=4;i!=0;i--)
for(j=100;j!=0;j--);
}
}
void EEP_Init(void)
{
FLASH_CR1 = 0x00;
FLASH_CR2 = 0x00;
FLASH_NCR2 = 0xff;
FLASH_DUKR = MASS_KEY1;
FLASH_DUKR = MASS_KEY2;
while(!FLASH_IAPSR_DUL);
}
void eep_write(uint addr,uchar dat)
{
*((uchar*)(addr + EEP_BASE)) = dat;
while(!FLASH_IAPSR_EOP);
}
uchar eep_read(uint addr)
{
return *((uchar*)(EEP_BASE + addr));
}
void main(void)
{
asm("sim");
EEP_Init();
while(1)
{
asm("nop");
}
}
|