Introduction to PIC Microcontrollers

PIC 16F628

PIC 16F628

PICs are great little chips, useful in all kinds of projects. Here is a run-down of some of the features contained in the chips, as well as potential uses.

How to start… Well, first off, what is a microcontroller? Well, the difference between a microcontroller (herein referred to as MCU or μC) and, say, a computer CPU is pretty big… Here’s a little chart of some of the typical differences:

  CPU MCU
Onboard instruction memory   +
Complex math routines +  
Super-high speed +  
General purpose   +
All-in-one   +
Built-in I/O ports   +
Low power consumption   +

Microcontrollers are intended for small, specific purposes, they have their own I/O ports, own memory, nearly everything needed is built in. You’ll find them in your microwave, refrigerator, car, camera, tv, all kinds of things…

The microcontroller I’ll tend to use in the beginning at least, is the PIC 16F628. It has 2048 words of instruction memory, plenty of data RAM, lots of EEPROM storage, a serial module, PWM, Input Capture/Compare, Comparators, etc… Lots of features. These may seem complex but ignore it, we’ll start out with super simple stuff and not use any of it til later (if ever!)

This chip runs at 20MHz, which is PLENTY for the purposes we’ll be putting it to, heck it’s an insane amount faster than needed. You can get them for about $4 at Digi-Key.

Schematic

Each of the pins you see there have a specific purpose, which is explained on the following page. A quick look @ the datasheet reveals this:

Legend:

  • <–> denotes a bi-directional data line
  • –> going INTO the chip denotes input-only
  • <– going OUT of the chip denotes output-only
  • the pins may have various labels, depending on how you decide to use them in your design
  • if a label has a BAR above it’s name (i.e. MCLR) it is active LOW, meaning the pin is “enabled” @ 0V instead of @ +5V

The 16F628 has 2 – 8bit data ports. They are the RA0..7 and RB0..7 you see on the diagram. Vss = Ground, and Vdd = +5V typically, and in my examples, always. CMPx are comparators, TX/RX are serial guys, etc, they are all described in the datasheet. For the first few tutorials, I’ll only be using them as straight digital outputs, no funky stuff.