Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The device you're using doesn't have internal non-volatile memory apart from its Flash, generally used for storing code.</p> <p>You have two options that I can see:</p> <ol> <li>Use some external Flash or EEPROM and interface it to the External Memory Bus that's available on this PIC (see page 97 of the Family Datasheet).</li> <li>Remap the internal Flash to reserve a small portion that can be used for storing your data (so that it doesn't interfere with the memory area used exclusively for code) and write your data into this region (page 87).</li> </ol> <p>I haven't worked with PICs for years, so can't offer you much in the way of implementation detail but I suspect there are many examples you can source from Microchip's website.</p> <p>In essence, the reason your code doesn't work is because you're trying to access memory that isn't there. If it is there, then the interface is not correct.</p> <p>EDIT:</p> <p>I've had a look through the code examples page for the PIC18 on Microchip's website and can't find any C examples for writing to the program memory. Unfortunately, it looks like you'll have to implement it in assembler. I don't know the semantics for the MPLAB compiler but, generally, it'll be <em>something</em> like this if you're going to do it inline:</p> <pre><code>void my_assembler_function(void) { // Inline assembler code, actioned via C. asm("MOV x y"); asm("MOV y z"); } </code></pre> <p>Alternatively, many C compilers for microprocessor's allow you to call an external <code>.s</code> file with a C function call, saving you from doing it inline.</p> <p>I think you can follow the example I found <a href="http://www.scribd.com/doc/55893269/50/Reading-and-Writing-Data-in-Program-Memory" rel="nofollow">here</a> to actually implement the functionality you're after.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload