Non-volatile memory on a PIC18F87J50
-
- 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
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.
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.
- 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
Hello,
Are you using Flowcode? If so which version and I'll see if I can generate you an example.
Are you using Flowcode? If so which version and I'll see if I can generate you an example.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Thanks.Benj wrote:Hello,
Are you using Flowcode? If so which version and I'll see if I can generate you an example.
I'm running Flowcode V8 (v8.2.1.13).
- 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
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.
Let me know how you get on.
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.
Let me know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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
also sorry for the slow responses i;m from Australia so the time zone thing is a bit of a problem .
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
also sorry for the slow responses i;m from Australia so the time zone thing is a bit of a problem .
-
- 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
Success
I know have working code thanks for all your help Benj .
I know have working code thanks for all your help Benj .
- Attachments
-
- Flash_18F87J50_r1.fcfx
- (10.58 KiB) Downloaded 222 times
- 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
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.
The code in the datasheet can often be generic and not quite right so you've done well to tweak it so it works.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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
Is there a specific chip in mind?
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
Is there a specific chip in mind?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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
Right now my current experiment is with the PIC32MZ0512EFE064.
I'm going to need to be able to store some variables..
Chad
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel