Problem:

Whenever I program a 16f877 (40 pin dip) with the config fuses set to
__CONFIG(BKBUG|CP1|CP0|WRT|BODEN|PWRTE|WDTE|FOSC1|LVP);

and the following code,

#asm
psect absdata,abs,ovrld,delta=2
org 0x2100
dw 00,02,03,04
#endasm

the chip NEVER can be re-programmed again. (well, at least with my picstart plus anyway). Can anyone help shed some light on what might be happening? I was __trying to put some initial values in the chips EEprom, while programming in MPlab, using hi-tec's C compiler. Now I have 3 dead $10 chips -- all with working (but not quite finished) code, that I cant re-program over. What have I done?

Answer

from:

Jim Robertson
NEWFOUND ELECTRONICS
Email: newfound@pipeline.com.au
http://www.new-elect.com
MPLAB compatible PIC programmers.
Set code protection to "ALL" and program just the config bits by using the PICSTART PLUS menu -> program/verify. Uncheck the program, ID and Data EEPROM options. and click program.

Now select code protection to "OFF" AND make sure the Data EE protect option is ALSO "OFF." Now reprogram the config bits just as you did above. You will now be able to rewrite to the DATA EEPROM and your $10 chips are saved.

Your config bit options need to set the CPD bit and this will prevent the problem occuring again.

__CONFIG(BKBUG|CP1|CP0|WRT|BODEN|PWRTE|WDTE|FOSC1|CPD)

(Delete the LVP mode if you are using the picstart plus)

This is just a guess at the syntax used. I am not farmiliar with the hi-tech compiler __Config directive. It seems to use OR and not AND like MPASM. If this is the case then it sucks bad!

What is happening is this. You are code protecting the data eeprom and therefore MPLAB will not be able to program new data into the data eeprom. To disable the data protection you need to MPLAB to issue the special break code protection command. This will break the program AND data protection. However MPLAB will only do this when it sees the program memory protection is enabled and not just when the data protection is enabled. The sequence I gave you turns on the program memory code protection and then MPLAB is forced to break the code protection before it can program the config bits second time around.

Interested:

See:

Questions: