📄 f_write.c
字号:
#include <ADUC812.H>
#include "f_adi.h"
/*---------------------------------------------------------
---------------------------------------------------------*/
unsigned long flash_write (
const void *buffer, /* Buffer to save */
unsigned long len, /* Buffer length */
unsigned long address) /* FLASH address to write to */
{
const unsigned char *s = buffer;
unsigned int i;
unsigned int addr;
/*-------------------------------------
If the address is too big, exit.
--------------------------------------*/
if (address >= ADI_EEMEM_SIZE)
return (0UL);
addr = (unsigned int) address;
/*-------------------------------------
--------------------------------------*/
for (i = 0; i < len; i++)
{
/*-------------------------------------
Read the page.
--------------------------------------*/
if ((i == 0) || (addr & 0x03) == 0)
{
EADRL = addr >> 2;
ECON = ADI_EE_READ_PAGE;
}
/*-------------------------------------
Update the data.
--------------------------------------*/
switch ((addr++) & 0x03)
{
case 0:
EDATA1 = s[i];
break;
case 1:
EDATA2 = s[i];
break;
case 2:
EDATA3 = s[i];
break;
case 3:
EDATA4 = s[i];
WRITE_EEPROM:
ECON = ADI_EE_ERASE_PAGE;
ECON = ADI_EE_WRITE_PAGE;
break;
}
/*-------------------------------------
Update the address.
--------------------------------------*/
if (addr >= ADI_EEMEM_SIZE)
break;
}
/*-------------------------------------
Write the final page IFF address is not
at the start of a new page.
--------------------------------------*/
if (addr & 0x03)
{
addr = ADI_EEMEM_SIZE;
goto WRITE_EEPROM;
}
/*-------------------------------------
-------------------------------------*/
return (i);
}
/*---------------------------------------------------------
---------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -