Non-volatile memory on a PIC18F87J50

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
jonathanm
Posts: 7
Joined: Mon Nov 11, 2019 11:03 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Non-volatile memory on a PIC18F87J50

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post by Benj »

Hello,

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

jonathanm
Posts: 7
Joined: Mon Nov 11, 2019 11:03 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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).

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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 212 times
Let me know how you get on.

jonathanm
Posts: 7
Joined: Mon Nov 11, 2019 11:03 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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 :) .

jonathanm
Posts: 7
Joined: Mon Nov 11, 2019 11:03 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post by jonathanm »

Success

I know have working code thanks for all your help Benj :) .
Attachments
Flash_18F87J50_r1.fcfx
(10.58 KiB) Downloaded 222 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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.

chad
Posts: 198
Joined: Sun Nov 04, 2018 7:13 pm
Has thanked: 27 times
Been thanked: 33 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post by chad »

Is a version of this possible on a pic32mx?

Chad

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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?

chad
Posts: 198
Joined: Sun Nov 04, 2018 7:13 pm
Has thanked: 27 times
Been thanked: 33 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Non-volatile memory on a PIC18F87J50

Post 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.

Post Reply