The Microchip PICmicro microcontroller series (known as the PIC) is extremely popular among both hobbyists and commercial designers. Its excellent I/O support, low cost, and versatility combine to make it an attractive option for low-end embedded applications.
A Low-End Microcontroller
In the embedded systems world, there are widely varying requirements of microprocessors and microcontrollers: from simple I/O controllers, to high-speed signal processors, and general purpose CPUs. Microchip's PICmicro series of microcontrollers falls from the low to medium end of this scale, fulfilling the simplest of needs with its 12C devices, and scaling up to more demanding requirements with its high-end 17C family. In the mid-range are the most commonly used devices, the 16C and 18C range; these give a good balance between low cost and high performance.
PIC Architecture
The PIC microcontroller started life as a piece of specialised industrial control logic. It grew out of General Instrument's Peripheral Interface Controller, slowly adding more microprocessor-like instructions, until it became a more general purpose machine. Much of its success is down to its low cost, both for the development tools and the microcontrollers themselves.
Because of the cost requirements of low-end microcontrollers, most PICs have very little RAM. Data memory is organised into 8-bit registers, ranging in number from 25 to 3840; only the 17Cxxx series supports externally addressed SRAM. Working with so little writable storage leads to a necessary rebalancing of programming style, making heavy use of look-up tables and unrolled loops wherever possible. While RAM is lacking, EPROM is not, ranging from 768 bytes to 128 Kbytes. The memory is organised as a Harvard architecture: the data memory is 8 bits wide, and the instruction memory is 12 to 16 bits wide, depending on the device.
Looking from a modern CPU architecture perspective, the PIC instruction set design has some unusual quirks. Due to the restricted instruction width, two-operand calculations use a special working register, denoted w. This design was common in the early days of microprocessors, where the working register was more commonly known as an accumulator. It allows for a very small instruction width, but slows execution due to almost continuous memory accesses.
An implication of the accumulator design is a highly verbose assembly language, and therefore very poor code density. Some seemingly simple operations, such as array manipulation, can take many more instructions than would be required on a modern architecture. Since low-end microcontrollers are primarily programmed in assembler, this arduously lengthy style of coding is less than ideal from a programmer's point of view.
Features
Combined with the low cost and size, the I/O capabilities of the PIC are what make it such an attractive proposition for interfacing projects. Even the 8-pin 12Cxxx devices have six I/O pins, and the more common mid-range 16C84 has thirteen. Many PICs also have multiple analogue input capability, using either reference voltage comparison or successive approximation methods, with 8-bit or 10-bit accuracy.
Programmable timers are also a standard feature, and many PICs have a hardware watchdog timer to allow resetting the processor if the program fails to function correctly. A useful complement to this is brown-out detection, allowing the system designer the option of halting the processor on a low voltage condition, instead of continuing and possibly operating incorrectly.
Many mid-range and high-end PICs are available with a built-in USART (Universal Synchronous/Asynchronous Receiver/Transmitter), which greatly assists serial interfacing. The maximum data rate is limited by the clock speed of the processor, but even a 20MHz external clock allows for asynchronous communications at up to 1250Kbaud.
One of the biggest selling points for enthusiast and educational users is the availability of the PIC in Dual In-line Package (DIP) format, which is readily mounted in breadboard or strip board. Many designs benefit from the fact that DIP chips can be built into a simple custom-designed circuit with exactly the I/O connections needed for the specific system being built.
Most other microcontrollers are only available in surface-mount configuration, which means that a pre-manufactured development board must be used as a basis for any home or university projects. Some microcontrollers are available in DIP format, but these tend to be available only in low volumes, and are therefore prohibitively expensive.
PICs are available in three memory configurations: one-time programmable (OTP), EEPROM, and Flash. Reprogrammable devices are intended for use in research and development, and cheaper OTP products are available in bulk for manufacturing. The low-cost OTP production capability of the PIC is one of the reasons it is so popular today, allowing microcontroller-based products to be mass-produced inexpensively.
Development Environment
Since the PIC is such a widely-used architecture, there is no shortage of software and associated development hardware aimed at developers. The most popular software includes Microchip's own MPLAB Integrated Development Environment, and a loose collection of GNU utilities.
MPLAB is a free collection of development tools, integrated in a Windows Multiple Document Interface application. It includes a simple text editor which is somewhat similar to the popular PFE32, a macro assembler, a build system, a rudimentary simulator, and drivers for a few Microchip EEPROM/Flash programmers. None of the components excel, but when combined are more than adequate for developing a full-scale software project.
Microchip and several third parties all offer C compilers targeted at various PIC instruction sets. Almost all of these are commercial, and those that are Free Software, freeware, or shareware tend to have very poor code density when compared to hand-crafted assembler. In any case, there is often little benefit to be gained from writing PIC software in C, since most of the work in developing for the microcontroller is interfacing with the hardware, and this is not helped by using the higher level language. For more complicated, algorithm-intensive tasks, using a C compiler may be a worthwhile trade-off; in simple interfacing projects, it is more likely that assembler will be the best choice.
Several GNU tools are available to aid PIC development; all of these are Free Software, and have been ported to most UNIX-compatible operating systems and Microsoft Windows. By far the most useful and popular of these is Scott Dattallo's gpsim simulator tool. This is well-known as the most full-featured and accurate PIC simulator available, allowing cycle counts, single instruction step, and full inspection of the microcontroller state. External hardware simulation support is available, including an LCD emulator, and support for USART and other more advanced hardware simulation is forthcoming.
Also available is
gputils, an MPLAB-compatible
assembler and
disassembler which is on a par with Microchip's offering. Completing the full development environment is a wide range of
drivers for PIC programmers, ranging from a
reverse-engineered driver for Microchip's own
PICstart+ kit, to several pieces of software which come with
circuit diagrams to build your own parallel port programmer. When combined with the user's choice of
text editor, standard GNU
make, and a
version control system, the Free Software offering is better in some ways than the Microchip option.
However, the GNU tools are not as easy to learn as MPLAB, and lack support for certain newer PIC devices and programmers. Those more familiar with a
Windows environment will certainly feel more at ease with MPLAB, and the GNU collection of individual tools is certainly a viable alternative for everyone else.
References:
"Programming and Customizing the PIC Microcontroller", Myke Predko, McGraw-Hill, 1998
Microchip: http://www.microchip.com/
GNUPIC Collection, Scott Dattalo: http://www.gnupic.org/
"PIC UART", Fr. Thomas McGahee: http://redrival.com/mcgahee (mirrored at http://penglet.org/picuart.asm)