Tom's Main Menu

Physical Computing Home

Intro to Physical Computing Syllabus

Networked Objects

Sustainable Practices

blog

Resources

code, circuits, & construction

my del.icio.us links

 

The PIC Microcontroller

 
PIC microcontrollers from Microchip are some of the most popular microcontrollers on the market today. PICs (programmable interface controllers) come in many varieties. There are very limited PICs that have a small number of input/output pins, and are capable of only digital input and output; there are PICs with numerous pins, PICs with built in analog-to-digital converters, PICs with built-in serial ports, with built-in USB capability, PICs with varying clock speeds and amounts of RAM and other features.

PICs also come in different physical packages. Some are very small, surface mount chips, designed for custom products. The ones we will be working with come in DIP (dual in-line package), PDIP (plastic DIP), and SPDIP (skinny PDIP) packages. These packages typically have the pins spaced 0.1 inches apart, and are convenient for the breadboards we typically use in prototyping.

PICs also vary in terms of their programming methods and reusability. Some PICs are one-time programmable (OTP), designed to be used for mass production. Others are windowed, meaning they have a window on the top of the chip that you expose to UV light in order to erase them for reuse. The most recent PICs are flash-programmable, meaning that they can be programmed and erased using just electronic signals from a PC, much like higher-level microcontrollers (BX-24 and BASIC stamps).

Which PIC you use for a project will depend on all of these different factors -- the physical size you need, the number and type of inputs and outputs, the speed, the RAM, the forms of external communication, and the price. In these notes, we'll use a handful of different PICs. With these PICs, we will be able to duplicate the functionality we get from the BX-24 and BASIC Stamp, but for a much lower cost and generally at a much higher processing speed. The tradeoff will be that we'll have to take care of a few more electronic details for the PIC that are built-in to the higher level processors.

The three PICs we'll be using are the PIC 16F819 (smallest, least features), the 18F252 (bigger, more features), and the 18F452 (biggest, most features). The biggest difference between them for our purpises is the number of input/output pins. Here's a breakdown:

PIC Digital I/O Analog Input Total I/O
16F819
16
5
16
18F252
23
5
23
18F452
34
8
34

* note: all of the analog input pins can be used as digital I/O pins as well

These notes apply for the most part to many of the flash PICs, beyond these three. Many of the PICs with the same number of pins as these have similar functionality, and code can be exchanged between them. For example, most code for the 18F452 will also run on the 16F877A and other 40-pin PICs. Likewise, code for the 18F252 will work for the 16F876A and other 28-pin PICs. Where these refer to 40-pin PICs, 28-pin PICs, and so forth, you can generally make these substitutions.

Wiring the PIC

Because different PICs have different configurations, you will need to read the data sheet to make sure you get the right pin configurations. There are a few things in common from one PIC to another to look for, however.

Vdd (Power) - Like every electronic component, you need power and ground. PICs run fine off +5V, and many can run off lower voltages as well. It's best to run your power through a 7805 +5V DC regulator.

Vss (Ground) - goes to ground.

CLKIN/CLKOUT - unlike higher level processor modules, the PIC has no clock crystal attached, and you have to attach one. A clock crystal and two 22-pF capacitors does the job.

MCLR - Master clear/reset. This is the reset pin. When you take it to ground, the PIC resets itself. Normally you connect it to +5V through a pull-up resistor (a 10K pull-up resistor is fine).

RA0-RA5, RB0-RB7, etc. - These are the input/output pins of the PIC. They are organized in I/O ports, each no more than 8 pins, labeled port A, port B, etc. Some PICs will have only one or two I/O ports (16F819 for example), while others may have as many as five (18F452). Some of the I/O port pins will have more than one function. For example, some pins may be attached to the hardware serial port, some may be attached to the analog inputs, and so forth.

Shown below are typical power and clock connections for the 18F452 PIC The pins that also function as analog pins are labeled, as are the pins that also function as serial communication pins:

Here are links for the 18F252 and 16F819 circuit diagrams as well.

For all my resources on the PIC and PicBasic Pro, see the PIC resources page.
Once you've built this much, you're ready to program the PIC.