read program memory with code protection bit is set

Thread Starter

bug13

Joined Feb 13, 2012
1,707
Hi guys

It maybe a stupid question, but I need to know for sure. If I set the code protection bit, can I still read data from program memory? As the pic I am using has no eeprom, and I need some way to store a few KB of data.

PS: I am using pic18f46j50

Thanks guys!
 

Thread Starter

bug13

Joined Feb 13, 2012
1,707
No, thats what the code protection is for.
I think you know I meant reading data in my application, not from a programmer. Just to make sure, I CANNOT read data out from my own application too?

How about writing data in program memory in my application?
 

JohnInTX

Joined Jun 26, 2012
3,801
To clarify, yes, your program can read data tables from the flash ROM using the conventional table read and write instructions. On this chip, the code protection prevents EXTERNAL reads when set but data tables in program flash can still be read.

You can also write to the flash to store/update data as the program requires. Be advised that its done in blocks and the PIC stalls completely during the few milliseconds it takes to write a block. Also, check the endurance of the flash to see how many read/writes it will take before 'wearing out'.

Some 18F parts have extensive CONFIG bits that you can use to prevent table reads/writes by the program, sometimes controllable in blocks of flash ROM. This does not seem to be one of them. Compare yours with the 18F6722 code/read/write protections.
 
Last edited:
Top