eeprom 的写操作比较费时,页写的效率要比字节高,但是页写需要控制地址卷页(roll),这里给出一个简单算法,欢迎讨论,希望有更简单的. //************************************************************** // Function: eeprom_prg_page // Programmer:ASTEC CHINA // Description:a simple page edge detect algorithm for page write of at24c02. // input para: // *data: write data pointer // addr: eeprom address // numb: write byte length // output para: none // modify history: 12/11/06 initia // 13//11/06 test pass //**************************************************************
void ext_eep_prg(unsigned char *data, unsigned int addr,unsigned char numb) { static unsigned char nlength, nlength_offset;
if(addr%8==0) //addr=n*8? { if(numb<=8) { nlength=numb; I2C_write_page(addr,data,nlength); } else { nlength=numb>>3; nlength_offset= numb%8; while(nlength--) { I2C_write_page(addr,data,8); addr=addr+8; data=data+8; } if(nlength_offset>0) { I2C_write_page(addr,data,nlength_offset); } } } else { nlength=8-(addr%8); if(numb<=nlength) { nlength=numb; I2C_write_page(addr,data,nlength); } else { I2C_write_page(addr,data,nlength); addr=addr+nlength; data=data+nlength; numb=numb-nlength; nlength=numb>>3; nlength_offset= numb%8; while(nlength--) { I2C_write_page(addr,data,8); addr=addr+8; data=data+8; } if(nlength_offset>0) { I2C_write_page(addr,data,nlength_offset); } }
} __RESET_WATCHDOG(); // wreeprom_exit_flag=1; } |