read program memory with code protection bit is set

Discussion in 'General Electronics Chat' started by bug13, Oct 27, 2015.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    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!
  2. Dodgydave

    Distinguished Member

    Jun 22, 2012
    No, thats what the code protection is for.
    bug13 and GopherT like this.
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    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?
  4. JohnInTX


    Jun 26, 2012
    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: Oct 27, 2015
    bug13 likes this.