void MCU_Write_Flash(const u8 *ptFlash_Data, u8 Data_Length, u16 Start_Addr)
{
u8 i = 0;
u16 WriteData = 0;
if(Data_Length > 0)
{
EECON1 = 0x84;
GIE = 0;
for(i=0; i<Data_Length; i++)
{
EEADRH = (u8) (Start_Addr >> 8);
EEADR = (u8) Start_Addr;
WriteData = *(ptFlash_Data + i);
EEDATH = (u8) (WriteData >> 8);
EEDATA = (u8) WriteData ;
EECON2 = 0x55;
EECON2 = 0xAA;
WR = 1;
asm("nop");
asm("nop"); //wait here for complete
Start_Addr++;
}
WREN = 0;
GIE = 1;
}
}
const u8 name[] = "1234567890";
const u8 cheky[] = "Cheky.Yao7";
MCU_Write_Flash(cheky,10,name);
只写入了cheky中Cheky.Ya八个字符,但少了两个,MCU_Write_Flash(cheky,12,name);时会正常。这是怎么回事啊。 |