title: How do you write and read to memory with PIC18?
body: <p>I want to store a number to PIC18 then retain it even if the power is lost or the unit is reset. I think my writing code portion looks fine, just the reading portion of it looks strange after the unit is reset.</p>
  
  <p>I am using the following code which I got from Microchip. </p>
  
  <p><strong>Code:</strong>  </p>
  
  <pre><code>unsigned int value;
  unsigned int DEEdata = 1;
  unsigned int  DEEaddr = 0x04;
  
  DataEEInit();
  dataEEFlags.val = 0;
  
  DataEEWrite(DEEdata,DEEaddr);
  value = DataEERead(DEEaddr);
  Nop();
  printf("%d",value);
  </code></pre>
  
  <p><strong>The ouput</strong>: 1</p>
  
  <p>However when I reset the unit and only use the reading code I always get 255. </p>
  
  <p><strong>Code to read</strong>:</p>
  
  <pre><code>DataEEInit();
  value = DataEERead(DEEaddr);
  printf("%d",value);
  </code></pre>
  
  <p><strong>The output</strong>: 255</p>
  
  <p>Why is this happening? I am assuming maybe the value is not being saved or the reading portion is incorrect. Thank you!  </p>