Electrical – Copy protect program code in PIC microcontroller

picpic16f

I'm trying to copy protect my code which i program in my PIC16F886 microcontroller. I've set the below CONFIG options in MPLABX and compiled it, got the output hex code. But no matter i set it, i'm able to read the program from the PIC microcontroller to a hex file.

I compared my original hex file, and the one i downloaded from the PIC microcontroller. Both have different text in it, but when i load the downloaded one to another blank device, it works exactly the same way my original compiled code works.

Am i doing something wrong? Why am i able to read the program even after setting the code protection bit. Kindly advise. Thanks.

#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#pragma config CP = ON          // Code Protection bit (Program memory code protection is enabled)
#pragma config CPD = ON         // Data Code Protection bit (Data memory code protection is enabled)
#pragma config BOREN = ON       // Brown Out Reset Selection bits (BOR enabled)
#pragma config IESO = ON        // Internal External Switchover bit (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)    

Best Answer

Figured out something myself..

When I program the device using MPLAB X IDE (using the Make and Program Device button) in the tool bar, with CP bit ON and try to read the program using MPLAB X IPE, it seems to be copy protected. I get an output hex file with all 3FFFs.

However, when i compile my project in MPLAB X IDE, generate an output hex file, use the hex file and program it to my device using MPLAB X IPE, and read the device to output the hex file, i'm able to download the working hex file from the device, even though it is copy protected.

Not sure if it is a bug in MPLAB X IPE or am i doing something wrong. I'm using version MPLAB X IPE v4.01

Just though of posting it here, as it may be helpful for someone facing similar issue. Thanks.