AnsweredAssumed Answered

[D-Flash] How to set initial value

Question asked by Pogo Lin on Sep 4, 2011
Latest reply on Sep 5, 2011 by Pogo Lin

Hi, 

I want to set a const variable with initial value in D-Flash segment and use this variable in some funtion. But if I set this variable with initial value and use it in other function. When I change this variable using writing D-Flash with user's input, this variable will not change. I checked the complier code, all code which using this variable will replace by the initial value. The following example code will express my issue.

#pragma DATA_SEG __EPAGE MYDFlashconst unsinged int uVariable = 10;#pragma DATA_SEG DEFAULTvoid main(void){   if( uVariable == 10 )  //<-- this line complier will not use uVariable, it will use 10      printf("OK");   WriterToDFlash();   if( uVariable == 5 )  // same above      printf("ok");   else      printf("write to D-flash failed");}void WriteToDFlash(){   //Write 5 to uVarialbe's address}

The run result will be

OK

write to D-flash failed.

My expection is OK and OK.

My question is how can I tell to complier don't using const value to replace variable and just use the value in varible's address. Please help me! Thanks a lot.

 

Pogo

Outcomes