1
\$\begingroup\$

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)    
\$\endgroup\$
  • 1
    \$\begingroup\$ Check the config word(s) in the hex file you wrote to the chip for its CP bit value. IIRc MPLAB has menu items that override what you specify in the code. Or your programmer might do something special with the CP bit. \$\endgroup\$ – Wouter van Ooijen Dec 15 '18 at 9:44
  • \$\begingroup\$ Also do check the content of the hexfile. CP bit causes the file to be incorrect, it does not prevent creation of a hex file \$\endgroup\$ – Cobusve Dec 15 '18 at 17:17
0
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's been a while since I used IPE but I think there are menu options to over-ride the config bits in the HEX file. Check those menu items. One of two things should be possible: either tell IPE to respect the config bits as written in the HEX file, OR use the menu items to force the config bits the way you want them to be programmed. \$\endgroup\$ – Dwayne Reid Dec 26 '18 at 7:44
  • \$\begingroup\$ Also ensure that MPLABX is set to generate "Production" rather than "Debug" code. \$\endgroup\$ – Dwayne Reid Dec 26 '18 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.