PIC Programmer for the Raspberry Pi



Chain Reversi is now available as an Android App!
Android app on Google Play

Circuit

The circuit for this project is quite simple. Its purpose is to adapt the GPIO pins of the Raspberry Pi to the voltages expected by the PIC. It also provides LEDs for diagnostic purposes.

Since different devices have different pinouts, I recommend that you build this circuit on a breadboard. Of course, you could adapt it for strip board, but I would suggest providing a mechanism to rewire the connections to the IC socket.

You could safely omit the diagnostic and testing LEDs. You will need to supply 12V externally to this circuit, as the Raspberry Pi does not have a voltage source that produces that high a voltage, and also make connectors to connect the Raspberry Pi to the circuit. I recommend connecting the GPIO to match the defaults for the software:

LineDefault GPIO Pin
VDD Control11
VPP Control9
Clock Control8
Data Out Control25
Data In24

RPi PIC Programmer Circuit Diagram

Component Count Value Example
R1, R2, R3, R6, R7, R11, R12, R16, R17 9 10kΩ, ±5%, 0.25W
R4, R5, R8, R9, R10, R13, R14, R15, R18, R19, R20, R21, R22 13 1kΩ, ±5%, 0.25W
C1, C2 2 1μF, 25V
LED1, LED2, LED3, LED4, LED5, LED6 4 General purpose standard or low power LED
Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8 8 General purpose NPN BJT transistor BC548
VR1 1 12V linear voltage regulator L7812CV
VR2 1 6V linear voltage regulator L7806CV
IC1 1 A supported PIC microcontroller PIC16F628

I'm currently working on specific links for these components, but I've had good experience with Farnell element14 - Electronics Distributor and they have a good selection.

Software

Currently, some of Microchip's 12 bit and 14 bit devices are supported (technically, 8 bit data word size, but 12/14 bit program word size):

It would not be difficult to add support for more similar devices. To do this, edit "Pic14Bit::s_chips" in pic14.cpp for 14 bit chips, or "Pic12Bit::s_chips" in pic12.cpp and "Arguments::s_ChipIdmap" in rpipic.cpp. Note: the PIC16F28 is recommended as this is the chip that I have tested most, and does not require circuit reconfiguration (such as the PIC16F54 does in order to make it boot). You should note that this software is very experimental, and likely has many bugs.

Building and Running

  1. Install scons, and a PIC assembler such as gpasm:
    sudo apt-get install gpasm scons
  2. Download and extract the RPiPIC software source to your Raspberry Pi. The current version of the RPiPIC software is: 2012100701.
  3. Change to the source directory and run:
    scons
  4. Test the circuit by running:
    sudo ./rpipic -r --device-id
    If you're using one of the recognised devices, you should see an output like:
    Reading device ID...
    Finished reading device ID...
    Detected chip: pic16f628
    Reading device ID...
    Finished reading device ID...
    :02400C00C007EB
    :00000001FF
    If you see:
    Reading device ID... Finished reading device ID... Could not find 14 bit chip with ID: 0x0000
    then there is something wrong with your circuit.
  5. If necessary, erase the PIC:
    sudo ./rpipic -e
    This command should also be sufficient to disable code protection if it has been enabled.
  6. Write a test program to the PIC:
    make -C samples
    cat samples/pic16f627.hex | sudo ./rpipic -pcdxu
    Note: samples/pic16f627.hex also works on the PIC16F628.
  7. To test the PIC program:
    sudo ./rpipic -b
  8. See what else the program can do:
    ./rpipic --help

Hopefully you'll be able to make some use of this. I've posted a thread on the Raspberry Pi forum, so if you have questions/feedback, please do post!