2
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\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
    Commented Mar 29, 2017 at 18:49
  • \$\begingroup\$ Are you programming for release or debug? \$\endgroup\$ Commented Mar 29, 2017 at 20:48
  • \$\begingroup\$ @BruceAbbott. I am programming for debug. Looked also at your answer. Going to investigate. \$\endgroup\$
    – Decapod
    Commented Mar 30, 2017 at 5:02

3 Answers 3

5
\$\begingroup\$

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!

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

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){
   while(1){};
};

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

\$\endgroup\$
1
  • \$\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\$ Commented Mar 30, 2017 at 18:09
0
\$\begingroup\$

Use MPLAB IPE and change the programming voltage to 5.125V. It works.

\$\endgroup\$
1
  • \$\begingroup\$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. \$\endgroup\$
    – Community Bot
    Commented May 22 at 9:02

Your Answer

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

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