N76E003跟stm8s003相比没有内部的eeprom,有教程通过用APROM分区(0x3800~0x38FF)作为内部eeprom使用;
- bit BIT_TMP;
- /* -------------------------------------------------------------------------*/
- /* Dataflash use APROM area */
- /* APROM 0x3800~0x38FF demo as dataflash */
- /* Please use Memory window key in C:0x3800 to check earse result */
- /* -------------------------------------------------------------------------*/
- UINT8 read_APROM_BYTE(UINT16 code *u16_addr)
- {
- UINT8 rdata;
- rdata = *u16_addr>>8;
- return rdata;
- }
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- /*****************************************************************************************************************
- write_DATAFLASH_BYTE :
- user can copy all this subroutine into project, then call this function in main.
- ******************************************************************************************************************/
- void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
- {
-
- UINT8 looptmp=0,u8_addrl_r;
- unsigned char code *cd_longaddr;
- unsigned char xdata *xd_tmp;
-
- //Check page start address
- u8_addrl_r = u16_addr;
- if (u8_addrl_r<0x80)
- {
- u8_addrl_r = 0;
- }
- else
- {
- u8_addrl_r = 0x80;
- }
- //Save APROM data to XRAM
- xd_tmp = 0x80;
- cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;
- while (xd_tmp !=0x100)
- {
- *xd_tmp = *cd_longaddr;
- looptmp++;
- xd_tmp++;
- cd_longaddr++;
- }
- // Modify customer data in XRAM
- u8_addrl_r = u16_addr;
- if (u8_addrl_r<0x80)
- {
- xd_tmp = u8_addrl_r+0x80;
- }
- else
- {
- xd_tmp = u8_addrl_r+0;
- }
- *xd_tmp = u8_data;
- //Erase APROM DATAFLASH page
- IAPAL = u16_addr;
- IAPAH = u16_addr>>8;
- IAPFD = 0xFF;
- set_IAPEN;
- set_APUEN;
- IAPCN = 0x22;
- set_IAPGO;
- //Save changed RAM data to APROM DATAFLASH
- u8_addrl_r = u16_addr;
- if (u8_addrl_r<0x80)
- {
- u8_addrl_r =0;
- }
- else
- {
- u8_addrl_r = 0x80;
- }
- xd_tmp = 0x80;
- IAPAL = u8_addrl_r;
- IAPAH = u16_addr>>8;
- set_IAPEN;
- set_APUEN;
- IAPCN = 0x21;
- while (xd_tmp !=0xFF)
- {
- IAPFD = *xd_tmp;
- set_IAPGO;
- IAPAL++;
- xd_tmp++;
- }
- clr_APUEN;
- clr_IAPEN;
- }
复制代码
单独的读写验证已经通过,但是当定义如下结构体之后,就无法进行写操作了,
- typedef_split3 DisMenu[7]=
- {
- {13,0x81,0x01},/* 'P' '1.' '1'*/
- {13,0x81,0x02},/* 'P' '1.' '2'*/
- {13,0x81,0x03},/* 'P' '1.' '3'*/
- {13,16,0x02},/* 'P' '-' '2'*/
- {13,0x83,0x01},/* 'P' '3.' '1'*/
- {13,0x83,0x02},/* 'P' '3.' '2'*/
- {13,16,0x04},/* 'P' '-' '4'*/
- };
复制代码
好像是你说的这种操作,Flash必须整页擦除?
一周热门 更多>