PIC 12F/16F/18F quick start
- 8 bits, 5-16MIPS (20-64MHz clock), 1.8 to 5.5 volts (lower voltages at reduced speed)
- 10,000 erase/write cycles enhanced flash program memory (typical), 10,000,000 erase/write cycles EEPROM data memory (typical)
- Huge selection of chips, many still in DIP packages. One of the most complete and full-featured families of microcontroller available on the market. Still manufacturing many "legacy" chips (eg the 16F84 circa 1993).
- PICs use a Harvard architecture where code and data memory are separate, unlike the von Neumann architecture used by the Intel Pentium. PICs use a RISC instruction set with between 33 (baseline) and 83 (PIC18) instructions. All instructions execute in one instruction cycle except for those that modify the program counter such as conditional branches and gotos which always need two cycles.
- One inexpensive, cross-platform (Windows, Linux, Mac OS X) device (Microchip's PICkit 2, see eBay for clones) programs and debugs most PICs
- Previously famous for a generous sampling program (now dead)
|Baseline Architecture||Mid-Range Architecture||Enhanced Mid-Range Architecture||PIC18 Architecture|
|Families||PIC 10, 12, 16||PIC 12, 16||PIC 12F1xxx, 16F1xxx||PIC 18|
|Interrupts||No||Single||Single - hardware context save||Multiple - hardware context save|
|Performance||5 MIPS (20MHz)||5 MIPS (20MHz)||8 MIPS (32MHz)||up to 16 MIPS (48MHz)|
|Instructions||33, 12 bit||35, 14 bit||49, 14 bit||83, 16 bit|
|Program Memory||up to 3Kb||up to 14Kb||up to 28Kb||up to 128Kb|
|Data Memory||up to 134b||up to 368b||up to 1.5Kb||up to 4Kb|
|Hardware Stack||2 level||8 level||16 level||32 level|
|Features||comparator, 8 bit ADC, data memory, internal oscillator||baseline plus: SPI/I2C, UART, PWMs, LCD, 10 bit ADC, Op Amp||mid-range plus: multiple comms peripherals, linear program space, PWMs with independant time base||enhanced mid-range plus: 8x8 hardware multiplier, CAN, CTMU, USB, Ethernet, 12 bit ADC|
|Highlights||lowest cost, smallest form factor||optimal cost to performance ratio||cost effective, more performance and memory||high performance, optimised for C programming, advanced peripherals|
Development and programming
IDE and compilers
- MPLAB X is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac OS X.
We use Microchip's free demonstration compilers with MPLAB. The demo compilers have certain optimizations that expire after 60 days, but we don't use those anyway.
There are many third-party compilers covering C, BASIC, Forth, JAL and Pascal: see PIC Resources:Third Party Compilers for a list.
There are many PIC programmers and debuggers, including some that you can build yourself. See PIC Resources:Programmers for a brief description of the most commonly used.
PICs do not ship with a bootloader, but there are many that you can program yourself. After the bootloader is installed, a programmer is no longer needed for simple firmware updates.
- ds30 Loader serial bootloader for most PICs (GPL), our favorite
- Diolan USB HID bootloader for PIC18F (GPL), another favorite
This is the most basic circuit required to program a PIC 18F2550. Most PICs require a similar minimum support circuit.
D1 is only needed by PICs that require a programming voltage greater than the power supply (see reset circuits below).
- PIC 12/16/18F run at 5volts, and lower voltages at reduced speed
- Connect all the supply pins to power (Vdd) or ground (Vss). Don't forget the AVdd and AVss pins
- Put a 0.1uF decoupling capacitor on each positive supply pin, and put it as close to the chip on your PCB as possible
- Reset is the MCLR/VPP pin on PICs (MCLR=master clear, VPP=programming voltage)
- Connect a resistor from MCLR to the supply voltage for normal operation, use 10Kohms for PIC 12/16/18
- The programmer uses 12-13volts on MCLR to put PIC 12F/16F/18F in programming mode. Use a small diode (D1) between the supply voltage and resistor (R1) to protect the supply voltage from the 13volt programming voltage
PICs use a 5 wire programming connection called ICSP in PIC datasheets. This is the prefered pinout order, it's compatible with the PICkit:
- VPP/MCLR - This pin is also the PIC reset pin. Used to enter programming mode, and reset after programming
- Supply voltage (from programmer, or to programmer)
- PGD - Program data, a bi-directional data pin (often PORTB7)
- PGC - Program clock (often PORTB6)
Programming a PIC usually requires connecting these five pins to a programmer.
Newer/larger PICs may have multiple pairs of PGC and PGD pins:
- Connect any pair you like
- You need to use the same pair (PGC2 and PGD2, for example)
- It's usually best to check the errata to be sure the pair you chose actually works
Most PICs have an internal oscillator that can be used as the clock source.
- An external clock source, resonator, or crystal can be attached to the OSC1 (input) and OSC2 pins.
- A secondary, low speed oscillator (T1OSO/T1OSI) is usually available for an external 32.768kHz crystal (real time clock).
Different PIC pins can source/sink different amounts of current. These are some general rules, but be sure to verify the capabilities in the datasheet for the exact device (usually a table at the beginning of the IO section).
- PORTA-D usually source/sink 25mA
- Others sometimes less
- 18F USB devices (5 volt parts) - An internal 3.3volt regulator requires a 0.22uF capacitor on the VUSB pin (we use 2 x 0.1uF), no other connections to VUSB are required
- PICs require a 48MHz internal clock for full-speed USB. This is derived by multiplying an external crystal with a PLL. Check the datasheet to be sure (Oscillator for USB section), but 20MHz and 16MHz will work on many PICs (18F2550, 18F25J50)
- All PIC USB peripherals have internal resistors, no other support circuitry is required
See PIC Resources for more information, third party compilers, operating systems/kernels, hardware (development boards), other tutorials and online PIC programming books.