请教IAR下STM8内部EEPROM的操作问题
1个回答
展开全部
#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");
}
}
#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");
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询