PIC Wars

The First Battle Won

I write this portion of the document after successfully winning my first battle with the PICs. I managed to build a programmer for the PIC16F84 and write some pre-built code to it. I then tested it out with a simple circuit, and voila, it worked. In my search for enlightenment, I found the PICLIST site quite useful. Check out their beginner's checklist. Here are the steps I used to get going:

  1. Build the NOPPP ("No-Parts" PIC Programmer). I tried using a 16F877 with the stripped down Tait programmer, but I failed to make it function. If anyone has had success with that simple setup, please let me know. I am still unsure of the state of my 16F877 chip, but I know now that my 16F84 is indeed working. The NOPPP is supposed to be modifiable for the 16F877, and that's what I'm going to be doing as soon as I test a bit more with the 16F84.
  2. Get the NOPPP Linux software. I tried the picprg software, but I was unable to make it function although it seemed like it should. The NOPPP software worked like a charm for the 16F84. If anyone has had success with the NOPPP under picprg, please let me know. The code I sent to the chip for the sample circuit is the 84flash.hex file available here.
  3. Build the test circuit. You'll need a 5V regulated power supply. There's a fairly good and not too complex one here. If you're new to electronics, here are a couple hints about capacitors that I had to relearn. The filled bar on the schematic is the negative side of the capacitor. On electrolytic capacitors, the negative side has the bar with the dashes on it. Once I had the power supply, I wired up the PIC as follows:

    1.  Pin 4 to +5V (MCLR normal operating setting)
    2.  Pin 5 to GND
    3.  Pin 6 to 220 Ohm resistor (1/4 watt, 5%).
    4.  Other end of resistor to positive side of LED.
        (Negative side of regular led is flat)
    5.  The negative side of the LED was connected to GND.
    6.  For the clock, I got a ceramic resonator.  I
        recommend the ones with capacitors built in.  I
        got a 4MHz one (CST4.00MGW) and it works well.
        The two sides of the resonator were connected to
        the two OSC pins on the PIC (Pins 15 and 16).  The
        middle pin on the resonator was connected to GND.
    7.  Pin 14 was connected to +5V and a .1UF monolythic
        ceramic capacitor was placed between Pin 14 and GND.

    After I had that set up, I plugged it in and the led blinked! Hurray!

Battle #2 - The Source Code

I wanted to test the 16F84's ability to load new code and I wanted to test my own ability to assemble and modify some existing pic code. I downloaded and installed gpasm for the task. BTW, a useful site for Linux PICing is gnupic.org.

I started out with the 84flash.asm file (from the above mentioned archive). I quickly discovered that gpasm is picky about tab placement in files. I ended up with the following file for my PIC16F84A. The hex code it generated was no different from the original .hex file. This was something of a reassurance to me. I then modified the code to use a different pin to blink by changing the LED_pin from 0 to 3.

It may be useful to note that these .asm and .hex files generate warnings. As far as I know the warnings may be disregarded. They haven't caused me any noticeable problems.

Another successful battle. Next I shall attempt to battle the evil PIC16F877.

Winning the War

After a bit of messing around, I have finally managed to program and reprogram the PIC16F877 chip. First, the NOPPP hardware needs slight modification.

The following modifications allow the NOPPP to program the 28 and 40 pin 16F87x family of PICs. The only extra hardware you will need is a 40 pin ZIF socket and a resistor. Connect the 40 pin socket to the 18 pin socket as follows:

18 pin	Signal	40 pin
======	======	======
4	MCLR	1
5	VSS	31
12	RB6	39
13	RB7	40
14	VDD	32

Additionally, connect pin 36 (RB3/LVP)
via a 1k-10k resistor to GND.

The original Blondini modification did nothing with RB3. However, based on this information, I chose to ground the RB3 pin via a 2.2k resistor. Any value from 1k to 10k should be okay. If you want to learn about unused/floating pins in general, take a look at this page.

The modifications match the pinouts of the 16F873, 16F874, 16F876, and 16F877. I haven't checked the 16F870 or the 16F871, but I imagine they might work as well. With the 28 pin chips, you will need to insert pin 1 of the chip into pin 1 of the socket. 18 pin PICs will not work in the 40 pin socket. Additionally, do not attempt to have PICs in both sockets simultaneously.

As for software, Blondini released a nicely modified version in the file noppp_V0.3.tar.gz. Thanks to the many people, including Blondini, who wrote in to notify me that the Blondini's PIC Page returned. I haven't tried it, but the software promises the following features:

  1. Added options for 16F873/4, 16C73/4 and 16F876/7
  2. Added the ability to read from a PIC
  3. Added a Hex file save option
  4. Added a verbose mode so you can see what you're reading/writing
  5. Replaced the timing code with calls to usleep(), this results in much lower CPU usage.
Although Blondini's software is available now, it wasn't available when I first created this page. Luckily, the software was simple enough, and the similarities between the 84 and 877 large enough that I managed to patch the noppp software to work with the 16F877. You can get the modified version here. I made the following changes from the original source:

  1. Set the parallel port to be 0x278 (usually lpt2) instead of 0x378 (usually lpt1). If you need a different port, change the base variable near the top of the file.
  2. Changed the CMASK for the 16F84 to 3FFF. The original mask of 3FF3 caused warnings that apparently had no effect and didn't make much sense in any case.
  3. Added the 16F877 chip option. If used with care (ie. don't overwrite memory that you don't have), this option should work for other 16F87x chips.
  4. Increased PSIZEMAX to accomodate the 8k memory of the 16F877.
  5. Added a return value to main() to avoid a warning.

The Test Circuit

I have a funky little movie of the PICs in action that you might want to download if you happen to have a broadband connection.

Once you have a 5V regulated power supply, you can wire up the test circuit as follows:

1.  Pin 1 (MCLR) to +5V
2.  Pin 11 (VDD) to +5V
3.  Pin 12 (VSS) to GND
4.  Pins 13 & 14 to side pins on ceramic resonator
5.  Middle pin on ceramic resonator to GND
6.  Pin 36 to GND via a 2.2k (1k-10k) resistor.  This
    prevents the chip from entering Low Voltage
    programming mode, since the bit may still be set.
    If you turn off the LVP config bit, you don't
    need this.
7.  Pin 32 to +5V
8.  Connect a .1uf capacitor between Pin 32 and GND.
    It's best to be as close to the chip as possible.
9.  Pin 31 to GND
10. Pin 23 to 220 ohm resistor (up to 1k should be ok).
11. Other side of resistor to the anode (positive side)
    of a LED.  The negative side is called the cathode
    and sometimes has a little flat spot on it.  The lead
    for the anode is sometimes longer.
12. Connected the LED cathode to GND.

The source file for this test circuit is first.asm. It can be compiled with gpasm into a useable .hex file. You may need to change the capitalization of the file in the include statement.


Electronic Basics
Basic information including schematic symbols for a variety of components.
A site with anything and everything related to electronics. They've got lots of projects and links to info on PICs and such.
Blondini's PIC Site
Has the NOPPP hardware and software modifications as well as a couple interesting PIC projects.

You're welcome to contact me if you have any comments or questions.

Return to Home Page