This article from http://blog.csdn.net/hellogv/, reference must indicate the source!
Flash-type MSP430 single-chip has information memory segmenga and segmentb, segmenga and segmentb each have 128 characters, segmentb address is: 0x01000h to 0x0000f, Segmenta address is: 0x01080h to 0x010ffh. After the program is written to MSP430, the program can save power-off data through segmenga and segmentb. Note: segmenga and segmentb will be erased every time the program is written to MSP430!
Next I will post the program code in this article and the flash data after the program is written into the Information Storage:
# Include <symbol xg43x. h> </P> <p> void writesegment_256 (char index, char * value, char size); <br/> char readsegment_256 (char index ); </P> <p> void main (void) <br/> {<br/> wdtctl = wdtpw + wdthold; // stop watchdog timer <br/> fctl2 = fwkey + fssel0 + fn0; // mclk/2 for flash Timing generator </P> <p> char str1 [3] = {0xaa, 0xbb, 0xcc }; </P> <p> writesegment_256 (0, str1, 3); </P> <p> for (char I = 0; I <255; I ++) <br/> _ Nop (); </P> <p> char str2 [3] = {0xbb, 0xaa, 0xcc}; <br/> writesegment_256 (0, str2, 3 ); </P> <p >}</P> <p> # define segmentstart 0x01000 // segment = 0x01000 ~ 0x010ff <br/> # define segmentsize 255 // Segmenta + segmentb = 256 </P> <p> //*************** **************************************** ** <br/> // read the data stored in the disk <br/> //******************** *********************************** <br/> char readsegment_256 (char index) <br/>{< br/> char * flash_ptr = (char *) segmentstart) + index; <br/> return * flash_ptr; <br/>}</P> <p> //************************** ************************* <br/> // write the array into the chip flash, all data must be erased before being written. <br/> // The index parameter stores the position of the array. <br/> // parameter value: array pointer <br/> // The parameter size: array size <br/> //******************************* * ******************** <br/> void writesegment_256 (char index, char * value, char size) <br/>{< br/> char buffer [segmentsize], I = 0; <br/> char * flash_ptr = (char *) segmentstart; </P> <p> // read the original flash array first <br/> for (I = 0; I <segmentsize; I ++) <br/> buffer [I] = readsegment_256 (I); </P> <p> // erased flash, required <br/> fctl1 = fwkey + erase; // set erase bit <br/> fctl3 = fwkey; // clear lock bit <br/> * flash_ptr = 0; // dummy write to erase flash segment </P> <p> // write the entire array into flash. <br/> fctl1 = fwkey + WRT; // set WRT bit for write operation </P> <p> for (I = 0; I <size; I ++) // modify the original array <br/> buffer [index + I] = value [I]; <br/> for (I = 0; I <segmentsize; I ++) // write data to flash <br/> * (flash_ptr ++) = buffer [I]; </P> <p> fctl1 = fwkey; // clear WRT bit <br/> fctl3 = fwkey + lock; // set lock bit <br/>}</P> <p>