Page 1 of 1

Non-volatile memory on a PIC18F87J50

Posted: Mon Nov 11, 2019 11:20 pm
by jonathanm
Hi I'm currently trying to read and write to the non-volatile memory of the PIC18F87J50.

I have been reading through Section 6 of the data sheet but can not seem to get any think to work.

If any one has any tips, example code and or help that would be great.

Re: Non-volatile memory on a PIC18F87J50

Posted: Tue Nov 12, 2019 11:06 am
by Benj
Hello,

Are you using Flowcode? If so which version and I'll see if I can generate you an example.

Re: Non-volatile memory on a PIC18F87J50

Posted: Wed Nov 13, 2019 8:13 pm
by jonathanm
Benj wrote:Hello,

Are you using Flowcode? If so which version and I'll see if I can generate you an example.
Thanks.

I'm running Flowcode V8 (v8.2.1.13).

Re: Non-volatile memory on a PIC18F87J50

Posted: Thu Nov 14, 2019 11:22 am
by Benj
Ok thanks,

Here's a simple example with macros to read, erase and write.

You must erase the row of memory before writing values.

I just copied the example code from the datasheet and substituted the variables for Flowcode variables.

It compiles but I haven't tested it any more than this.
Flash_18F87J50.fcfx
(10.88 KiB) Downloaded 248 times
Let me know how you get on.

Re: Non-volatile memory on a PIC18F87J50

Posted: Mon Nov 18, 2019 12:54 am
by jonathanm
Hi Thanks for your help :)

I had to change the code slightly to get the read function to work.

TBLPTRU = FCV_H;
TBLPTRH = FCV_M;
TBLPTRL = FCV_L;

#asm

TBLRD*+ ; read into TABLAT and increment
MOVF TABLAT, W ; get data
MOVWF _FCV_EVEN
TBLRD*+ ; read into TABLAT and increment
MOVF TABLAT, W ; get data
MOVWF _FCV_ODD

#endasm


so it work well thanks.

when i try and use the wright function i get a compiler error.

EEPROM SAVING 20191118.c: 3014: (876) syntax error
EEPROM SAVING 20191118.c: 3015: (876) syntax error
EEPROM SAVING 20191118.c: 3010: (800) undefined symbol "WPROG"
EEPROM SAVING 20191118.c: 3011: (800) undefined symbol "WREN"
EEPROM SAVING 20191118.c: 3012: (800) undefined symbol "GIE"
EEPROM SAVING 20191118.c: 3017: (800) undefined symbol "WR"
(908) exit status = 1
(908) exit status = 1

Error returned from [xc8.exe]


not sure how to fix this but I will try :shock:

also sorry for the slow responses i;m from Australia so the time zone thing is a bit of a problem :) .

Re: Non-volatile memory on a PIC18F87J50

Posted: Mon Nov 18, 2019 6:10 am
by jonathanm
Success

I know have working code thanks for all your help Benj :) .

Re: Non-volatile memory on a PIC18F87J50

Posted: Mon Nov 18, 2019 10:50 am
by Benj
Excellent well done and thanks for letting us know.

The code in the datasheet can often be generic and not quite right so you've done well to tweak it so it works.

Re: Non-volatile memory on a PIC18F87J50

Posted: Wed Nov 20, 2019 2:22 pm
by chad
Is a version of this possible on a pic32mx?

Chad

Re: Non-volatile memory on a PIC18F87J50

Posted: Wed Nov 20, 2019 2:32 pm
by Benj
Yes probably,

I want to make a component to drive it but it's complicated to cover all devices. I'm slowly getting to grips with the associated code. The PIC32 likely breaks all these rules anyway :wink:

Is there a specific chip in mind?

Re: Non-volatile memory on a PIC18F87J50

Posted: Wed Nov 20, 2019 2:39 pm
by chad
LOL, yeah I have a unique ability to pick hard to use things it would seem.
Right now my current experiment is with the PIC32MZ0512EFE064.
I'm going to need to be able to store some variables..

Chad

Re: Non-volatile memory on a PIC18F87J50

Posted: Wed Nov 20, 2019 5:52 pm
by Benj
Hi Chad,

Ok for that device there is no example code in the datasheet however I did stumble across this MIcrochip forum topic which looks relevent.
https://www.microchip.com/forums/m722793.aspx

Specifically this example.
http://ww1.microchip.com/downloads/en/D ... 041613.zip

Looking at the datasheet it looks like the smallest block you can erase is a single page which is 4KB. So not ideal by any means but possible if you have say 8KB of program flash to throw away in creating a none volatile data area. You would erase one of the 4KB blocks and then copy the data from the other block to the newly erased one plus the new value you want to write.