0
votes

I am using the following library <flash.h> to Erase/Write/Read from memory but unfortunately the data I am trying to save doesn't seem to be written to flash memory. I am using PIC18F87j11 with MPLAB XC8 compiler. Also when I read the program memory from PIC after attempting to write to it, there is no data on address 0x1C0CA. What am I doing wrong?

char read[1];
  /* set FOSC clock to 8MHZ */
OSCCON = 0b01110000;

/* turn off 4x PLL */
OSCTUNE = 0x00;

TRISDbits.TRISD6 = 0; // set as ouput
TRISDbits.TRISD7 = 0; // set as ouput

LATDbits.LATD6 = 0; // LED 1 OFF
LATDbits.LATD7 = 1; // LED 2 ON

EraseFlash(0x1C0CA, 0x1C0CA);
WriteBytesFlash(0x1C0CA, 1, 0x01);
ReadFlash(0x1C0CA, 1, read[0]);


if (read[0] == 0x01)
    LATDbits.LATD6 = 1; // LED 1 ON

while (1) {


}
1
Are you sure ReadFlash(0x1C0CA, 1, read[0]); shouldn't be ReadFlash(0x1C0CA, 1, read);?D Krueger
Either way it doesn't work, because there is nothing written to memory at all when I read the program memory from the PIC.Ammar
but you are right it should be read instead of read[0]Ammar

1 Answers

1
votes

I don't know what WriteFlashBytes does but the page size for your device is 64 bytes and after writing you need to write an ulock sequence to EECON2 and EECON1 registers to start programming the flash memory