Hi, the problem is that the compiler uses MOVX instead of MOVC when I'm reading the rom, of course it doesn't work. There's no problem to write the flash. I don't want to add an assembly routine. Is there any other solution? I'm using Silabs C8051F020.
Thanks.
Write in flash only clear bits, so you have to initialize the code variable with 0xff, or erase the entire block before write.
unsigned char xdata variable[2]={0x46,0x11}; unsigned char xdata variable_2[2]={0}; unsigned char code string_1[2]={0xff,0xff};
write_flash(string_1,variable); //writing to flash
variable_2[0] = string_1[0]; //reading from flash variable_2[1] = string_1[1];
Thank you.
" ... so you have to initialize the code variable with 0xff"
Eh?!
If writing can only clear bits (as, indeed, is usually the case with flash), then how can you initialise the variable to 0xFF other than by erasing?!
You do it by originally storing the value 0xff in the variables while flashing the program. Then the program may replace these 0xff with other values.