Burning a PIC

This little project turned out to be a nightmare. But a lot of the problems were self-imposed, if I were to be truthful. I had already developed a bit of code that programmed a P16F877A. That was written in assembly language. I thought the conversion to C, creation of a video, and the WEB page write-up would take three days, tops. But I had one problem after another. Rather than go into it here, I will probably write a blog about development issues, learning issues, dealing with problems, and staying motivated

So, finally, I can burn a PIC with C code. The major change to the python host code involves the detection of the Configuration Word, sending it to the programmer, and receiving the echoed CW. Changes to the programmer code were fairly extensive.

Python Host Changes

I apologize for the white-on-black code review in the video. I will not do that again.

I‘m probably taking a chance with the way I’m detecting and processing the Configuration Word. The xc8 compiler I’m using generates a line in the Intel hex file that has the address of the CW and the two bytes (four ASCII characters) that are the value to be programmed. That’s all well and good. For every line read from the hex file, I check for this address of 0x2007. I then assume that the only data on the line is the value for the CW. I read from that fixed position on the line and send it to the programmer. I can imagine several things going wrong with this:

  • Configuration Word line in hex file could change:
    • Specifying ID data might be combined with CW.
    • The address could change and the CW would not be detected at all.
  • The CW location in memory is not a simple address change:
    • The command to program the CW forces the target PC to address 0x2000.
    • The only way to return to program memory space is to exit/reenter programming mode.

Currently, there is no provision to handle any of these possible situations.

Programmer Code Changes

A list of the major changes:

  • Declare bit in TRISB to control the PGD direction.
  • address_init( ) handles target address changes (not tested).
  • prog_conf( ) receives CW word and calls:
  • load_conf( ) programs the target with the CW and calls:
  • word_read( ) read a word from the current target PC (will work for program memory also).
  • program_target( ) programs up to a 240 byte block of code into target.
  • All erase functions have an internal-to-programmer path and an external-request path.

This is all very basic and minimal functionality at this point. More complicated (i.e. code-blocks spaced out in memory) hex files have to be tested. Functionality needs to be added to prevent lock-ups caused by miss-communication. If a command/acknowledge sequence is missed both programmer and host can be caught in a dead-lock. And the timing can be improved where margins are a little too large.

This is a pretty short page for all of the effort that went into it. Most of the info is in the sources. So you need to spend you time reading code anyway. Don’t know when I’ll add to this project. It no doubt will be the addition of capability to program an ATmega328P. I think that mixing targets in the programmer code will cause structure changes that probably should be ironed-out before some of the “fine tuning” is done. We’ll see.


The schematic is as basic as possible. the Vpp (high-voltage) programming wire has to be removed/inserted for the proper functionality. But that’s just like plugging/removing the PICkit3. As noted, the Vpp transistor circuit will be modified to become electrically dead when desired by adding another transistor and a new configuration. As always, use at your own risk.

Programmer Schematic


Here is the download for this video and page. I’m will just include one download for linux/Windows. Everyone can handle zip files, Windows has tools to read “\n” terminated strings, and I’m going to remember to replace all tabs with spaces in text files. The download includes:

  • prog_2550.c – C programmer code.
  • dnld.py – python host GUI.
  • burner_test – .asm and .hex files for programming the target.
  • programmer_schematic_II.pdf – the current state of the programmer circuit.
    Download Programmer Project:  programmer-0.2.zip