is a great chip
s with; as mentioned above, it has plenty of flash memory
space, and a programmer
costs almost nothing. There is plenty of excellent documentation
's website (www.microchip.com), including detailed (and easy to understand) datasheet
s and application note
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.
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.
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 wheel
s, 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.
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 level
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 device
s. The following is a small program that you can use to check if your oscillator is actually running:
init BSF STATUS, RP0
BCF STATUS, RP0
start INCF PORTA
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.