I am building a program for a PIC16F877A. It seems to be running correctly in the simulator MPLABX. I'm using about half the available program and data memory.

During programming I receive the following message:

The following memory area(s) will be programmed:
program memory: start address = 0x0, end address = 0xfff
configuration memory
Debug Executive
Address: 1f00 Expected Value: 1170 Received Value: 3fff
Failed to program device

Under the simulator situation I have looked in the program memory. Address 1F00 is not used and has indeed the value 3FFF. How to proceed in finding the error?

The program is written in XC8.

  • \$\begingroup\$ Are you using the pickit3 in "high voltage" programming mode? I haven't used this in a while, but if you're trying with some low-voltage programming, maybe it can't change the configuration word. \$\endgroup\$
    – pipe
    Mar 29, 2017 at 18:49
  • \$\begingroup\$ Are you programming for release or debug? \$\endgroup\$ Mar 29, 2017 at 20:48
  • \$\begingroup\$ @BruceAbbott. I am programming for debug. Looked also at your answer. Going to investigate. \$\endgroup\$
    – Decapod
    Mar 30, 2017 at 5:02

2 Answers 2


For hardware debugging an extra piece of code called the 'Debug Executive' is loaded into program memory from 0x1F00-1FFF. For some reason your programmer is not able to write to this area. Three possible causes I can think of:-

  1. The Flash is Write protected.

Ensure that all program memory is writable by adding #pragma config WRT = OFF to your code.

  1. You actually have a PIC16F877 (no 'A'), which has different configuration bits.

The 16F877 can be configured to write protect 0x1F00-1FFF while leaving other areas alone. Solution is to select the correct MCU and set the appropriate configuration bits for it.

  1. The chip is faulty, or it's actually some other PIC that only has 4k words of program memory.

Try padding the program until it fills more than half the memory, then if programming fails above 0x1000 you know it only has 4k of working Flash!

  • \$\begingroup\$ The Flash was Write protected due to an unexpeced behaviour of a define in the header file. See my answer \$\endgroup\$
    – Decapod
    Mar 30, 2017 at 11:24

Error found.

The configuration bit WRT changed from OFF to HALF at the moment the compiler started. So I commented all the source code and left

void main(void){

No succes. With only xc.h No Problem. My header causing problems!!

#define ON  1
#define OFF 0

caused to change WRT from OFF to HALF

  • \$\begingroup\$ Interesting! I see the generated source code for configuration settings has this comment - "Use project enums instead of #define for ON and OFF" Now we know why! \$\endgroup\$ Mar 30, 2017 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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