在flash中写数据时,考虑到跨页问题,分数次写人数据到FLASH中,而缓冲区不可太大,取512字节长度,正好一页,我刚试过了,好象不行!!程序如下: buffer:数据源地址指针 flashaddr:数据目标相对地址,位于第16扇区,范围0~8K-1 length:待写入字节长度 UINT8 WriteToMemory(UINT8 *buffer, UINT16 flashaddr, UINT16 length) { UINT16 writesize; BlankCheck( Sector_16, Sector_16 ); // 查空 if( paramout[0] == SECTOR_NOT_BLANK) // 非空擦除 { SelSector( Sector_16,Sector_16 ); EraseSector( Sector_16,Sector_16 ); // 擦除第16个扇区 } while( (flashaddr+length)>(flashaddr|0x1ff) ) //跨页 { writesize = 512-flashaddr&0x1ff; WriteToPage(buffer, flashaddr, writesize); //写一页 flashaddr += writesize; buffer +=writesize; length -=writesize; } WriteToPage(buffer, flashaddr, length); return paramout[0]; } |