title: Erasing flash memory in blocks (1024 bytes)
body: <p>I am working on making a bootloader. I have to erase 1024 bytes of memory before I write anything to those registers in that block. Even if I want to write 2 bytes, I am forced to erase 1024 bytes. My problem is that I don't know where each block starts. For example, lets say I want to write the following bytes to this address. </p>
  
  <p><strong>Address:</strong> <code>0x198F0</code></p>
  
  <p><strong>Bytes:</strong><code>C80E00010001616FDFECD6F08C8C92EC</code></p>
  
  <p>When I try to erase 1024 bytes starting from address <code>0x198F0</code>I noticed that it starts erasing from <code>0x19800</code> instead. </p>
  
  <p><strong>How do I know where each block starts from so I can calculate it in software?</strong></p>
  
  <p>The reason I want to know this is so I can copy the entire block into ram before I erase it, then modify it, and write it back to the same block. I am using <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/39778b.pdf" rel="nofollow">PIC18f87J11</a> with MPLAB XC8 compiler. I hope its clear what I am trying to do, otherwise let me know in the comments. </p>
  
  <p>Thanks!</p>