PIC 12F/16F/18F quick start

From DP

Revision as of 14:10, 23 November 2010 by Dpropicweb (Talk | contribs)
Jump to: navigation , search

Contents

Features

  • Huge selection of chips, many still in DIP packages
  • 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 just 35 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 (PICkit 2, see eBay for clones) programs and debugs most PICs
  • Previously famous for a generous sampling program (now dead)

Reference

Development and programming

IDE and compiler

  • 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 C, BASIC, and Pascal compilers too

  • SDCC is an open source C compiler for some PICs
  • JALv2 is an open source JAL (Just Another Language) compiler. JAL is a high level language designed to hide the general nuisance of programming a Microchip PIC. It is derived from the original JAL, by Wouter van Ooijen, which is loosely based on Pascal. JAL compiles code for baseline, midrange and the 18F PIC series. Extensive libraries are available for JAL and there is an IDE called JAL Edit. The JALv2 compiler is cross platform running under Windows, Linux, FreeBSD and Mac OS X.
  • Great Cow BASIC An open Source BASIC compiler for Microchip PIC (and Atmel AVR) microcontrollers. There's also Great Cow Graphical BASIC which is an icon-based program editor. It allows you to create Great Cow BASIC programs without having to memorise commands. This makes it particularly useful for those who have never before done any programming.

Programmers

  • PICkit 2 The hobbyist's choice. A powerful programmer and debugger with cross-platform programming software (Windows via the MPLAB IDE, standalone application and command line application; Linux - with source code; Mac OS X - with source code). Debugging is only available with the Windows MPLAB IDE software. Additional Windows-only software is freely available from the Microchip website for a UART Tool (use se the PICkit 2 for PIC MCU serial communications) and a Logic Tool Analyzer (use the PICkit 2 to capture digital waveforms in a circuit). The PICkit 2 can also be used to program microcontrollers without being attached to a computer (Programmer-To-Go feature). Since the release of the PICkit 3 in 2009 (see below) Microchip have hinted that they will not add support for newer microcontrollers, but this does not seem to have been the case to date. There is also a user-created tool, the PICkit 2 Device File Editor which makes it easy(ier) to add new devices yourself. Note that some device are not supporte in the MPLAB IDE but require the use of the standalone PICkit 2 programming application.
  • PICkit 2 clones Microchip made the PICkit 2 schematic, firmware and software freely available from their website and this has encouraged a slew of Chinese clones and a small number of enhanced, more expensive, clones. See eBay for current clones, but check vendors' own websites which may be cheaper (but watch the shipping charges!).
  • PICkit 3 Beware the newer PICkit 3. It is more like an ICD2 rather than a PICkit 2. From a hardware viewpoint, the PICkit 3 is a hybrid of PICkit 2 and the ICD 2; from a software viewpoint, it is purely an ICD 2. None of the good software architecture of PICkit 2 has shown up in PICkit 3 (yet anyway). The UART Tool and the Logic Tool Analyzer Tool are not available for it. The only programming and debugging software available for it is the Windows MPLAB IDE. To top it off it costs more than the PICkit 2 for significantly less functionality. The only reason you might consider it is that Microchip has committed to support it for future microcontrollers.
  • ICD 2 Superseded by the newer, cheaper ICD 3 (see below). Avoid.
  • ICD 3 In-Circuit-Debugger. Faster programming than a PICkit, but 4 times more expensive (or more compared with PICkit 2 clones). Also requires the purchase of additional header boards with a special microcontroller for debugging Some 8-, 14- and 18-pin PIC microcontrollers.

Build your own

Bootloaders

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.

Basic circuit

Power

  • Connect all the supply pins to power or ground. Don't forget the AVcc and AVdd pins
  • Put a 0.1uF decouple capacitor on each positive supply pin, and put it as close to the chip on your PCB as possible.

Reset

Two schematics: with and without MCLR diode

  • Reset is MCLR/VPP (voltage programming) on PICs
  • Connect a resistor from MCLR to the supply voltage for normal operation, use 10Kohms for 12/16/18, use 2Kohms for 24/30/33
  • 12F/16F/18F - The programmer puts 12-13volts on MCLR to put the PIC in programming mode. Use a small diode between the supply voltage and resistor to protect the supply voltage from the 13volt programming voltage
  • 24F/30F/33F - The programmer holds MCLR low and enters a key to start programming mode. No high voltage is used, no protection diode is needed.

Programming connections

PICs use a 5 wire programming connection called ICSP in PIC datasheets.

  1. VPP/MCLR - This pin is also the PIC reset pin. Used to enter programming mode, and reset after programming
  2. Supply voltage (from programmer, or to programmer)
  3. Ground
  4. PGC - Program clock
  5. PGD - Program data, a bi-directional data pin

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), and it's usually best to check the errata to be sure the pair you chose actually works.

Crystal

Peripherals

IO

USB

Ethernet