Extremely popular microcontroller manufactured by Microchip Technology Inc. based around their PIC architecture. The heart of the 16x8x series is a Harvard architecture core with a 33 instruction RISC ISA, 14 bit instruction wordsize and an 8-bit data bus. The '84 is a hobbyist's dream because it has 1K of built-in nonvolatile program memory and a simple and inexpensive method of code downloading. Programming hardware for the PICs can often be built from junk box sweepings.

The PIC16F84 is a great chip to learn about microcontrollers with; as mentioned above, it has plenty of flash memory space, and a programmer costs almost nothing. There is plenty of excellent documentation on Microchip's website (www.microchip.com), including detailed (and easy to understand) datasheets and application notes.

If you're going to get into the 16F84, there are some parts you'll use a lot of:

  • veroboard. Get the biggest piece you can find and chop it up.
  • 1-10k resistors. Mainly for pullup/downs.
  • Whatever parts you're using for your oscillator. I use 4MHz crystals with 33pF capacitors, but you may want to use an RC oscillator to save money. Buy lots.
  • 18 pin IC sockets. More on this below.
  • 5V1 zener diodes. Lots of stuff in the outside world uses voltages above 5V; these come in handy to make sure you don't nuke your PIC.
  • Lots of 1N4148 diodes. Just buy a pack of 100 or so and be happy (they're only a few cents each).
  • A good LED source is handy; also get some 120-400 ohm resistors to save you blowing anything up.
  • A power source. I use four Ni-Mh AA cells in a holder; this gives around 5.2V most of the time. You want something in the range of 4.5-5.5 volts, although the chip isn't fussy. Current drain is pretty much a non-issue - a few milliamps at most.

IC Sockets

Buy lots. If you're going to be experimenting with the 16F84, you'll be building lots of test circuits. I like to buy a bunch of dual-wipe sockets (the cheap ones, only a few cents each) to put in each circuit, and then buy one socket which stays with the chip (so when the chip is inserted in a circuit, there's actually two sockets between it and the circuit board.

Why? If you're moving the PIC around a lot, between your test circuit and the programmer, the pins are going to wear out quickly - more likely, you'll end up snapping them off after a few program->test->debug cycles. Some people use the more expensive machine pin sockets for the PIC - the pins won't bend and break like with the dual wipes, but the sockets you're plugging it into won't last as long, and they're harder to insert and remove.

Software Tools

gpsim is by far the best PIC simulator. It runs under Linux (or whatever other *nix you're running). For Windows people, Microchip's MPLAB is probably the best, but it takes some getting used to. gpsim is purely for simulation (if you want to change the program, you have to recompile and reload the .cod file, and start your sim all over). MPLAB is basically a simulator tacked onto PFE32, an excellent text editor for Windows (along with its long-standing bugs - wierdness with mouse wheels, dodgy wordwrap, etc). It's not very fast (delay loops will drive you insane) but it does the job.

Assemblers - gpasm is very nice and fast, but again, is Linux only. MPASM does a good job too, but is fussier about #included files, and whines about using registers in banks other than 0 (among other minor flaws).

Programmers - I've only ever used ICProg (Windows). It handles JDM programmers, has a nice display and decompiler, and, well, it works. The only argument I have is that, as far as I can tell, there's no source available.

RS232 Interfacing

This gave me major headaches when I was first trying to do it, since I didn't want to use the MAX232 chip. There are two main problems; generating the oscillator frequency, and generating the right output levels.

The oscillator can be generated in software or hardware. For a PIC that will be sitting mostly idle, software will work fine. The usual technique is to use the timer interrupt (with an appropriate prescaler) and count the right number of interrupts, and then maybe a delay loop to make the period more accurate. This only works for very low bitrates though.

The more accurate method is to use an external crystal. Finding the crystals might be tricky, but remember that you can keep count in software of how many times the interrupt has triggered to get useful dividers. Usually you need a buffer/inverter to do the actual logic level generation for the PIC; I use a 74HC04. There are plenty of examples of this circuit on the web.

The output levels are the other problem. I spent a lot of time messing around with sniffing +/-12V from the serial port, and eventually found out that the normal 0-5V logic levels are just fine. The only trap is that everything is inverted.

How do I know if it's working?

This is always a problem, especially with LCD circuits, since you can't tell if anything is actually happening if nothing appears on the output devices. The following is a small program that you can use to check if your oscillator is actually running:

        LIST P=16F84
        include "p16f84.inc"
        ORG	0
        GOTO init

init    BSF STATUS, RP0
        CLRF TRISA
        CLRF TRISB
        BCF STATUS, RP0

start   INCF PORTA
        INCF PORTB
        GOTO start

You'll need to make sure you've chosen the right oscillator settings in your programmer. Turn ON the powerup timer, and turn OFF the watchdog timer (although those two shouldn't really matter anyway).

A lot of this program can probably be trimmed down, but it should work in almost any circuit (so long as the I/O pins aren't being driven, but it's probably safe even then, so long as nothing gets hot). The basic idea is: the init section makes the I/O pins outputs. Then it loops through the two INCF statements as quickly as it can.

To make sure everything is working, check the following voltages:

  • pin 4 (/MCLR): 5V
  • pin 5 (GND): 0V
  • pin 14 (+5V): 5V
The two oscillator pins (15 and 16) will depends on what type of oscillator you're using. Every other pin should be at 2.5V (or thereabouts).

Being a technical node, I've probably fucked up somewhere. PLEASE /msg me if you notice anything that needs to be fixed or improved.

Log in or register to write something here or to contact authors.