本帖最后由 wang12zhe 于 2013-6-11 21:56 编辑
本来是测试自己的flash操作函数,但是感觉执行的过程中程序被擦出了
程序如下:
void main()
{
unsigned int cpt;
while(1)
{
LED_LEARN =ON; // LED3
Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);
Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);
LED_LEARN =OFF; // LED3
Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);
Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);Delay_1ms(250);
/*----- Fill block 1 with 0x55 ---------------------------------------------*/
/*--------------------------------------------------------------------------*/
for (cpt = 0; cpt< 0x10; cpt++){
tab[cpt] = 0x55;
}
//============先写入测试数据
for (cpt=0xc000; cpt<0xdFFF; cpt=cpt+0x10){
__api_wr_code_page(cpt, (unsigned int)tab ,0x10);
}
//=========然后 读出写入的数据
for (cpt=0x2000; cpt<0x4000; cpt++)
if(__api_rd_code_byte(cpt)!=tab[0]){
display_string_16x8(1,2,"1S",2);
break;
}
else{
if (cpt == 0x3FFF){
display_string_16x8(1,2,"1F",2);
}
}
/*----- write code address 0x1500 with 0x33 --------------------------------*/
/*--------------------------------------------------------------------------*/
__api_wr_code_byte(0x1500,0x33);
if(__api_rd_code_byte(0x1500)!=0x33){
display_string_16x8(3,2,"2S",2);
}
else{
display_string_16x8(3,2,"2F",16);
}
__api_erase_block(BLOCK_1);
__api_erase_block(BLOCK_2);
__api_wr_code_byte(0x1500, 0xFF);////在到对应位置写入0xff 即可完成擦出
for (cpt=0x2000; cpt<0x8000; cpt++){
if(__api_rd_code_byte(cpt)!= 0xFF){
display_string_16x8(5,2,"3S",16);
break;
}
else{
if ((cpt == 0x7FFF) && (__api_rd_code_byte(0x1500)==0xFF)){
display_string_16x8(5,2,"3F",16);
}
}
}
}
那个LED灯亮一次,灭掉后就再不亮了,所以怀疑程序被擦出了,求解 |