PIC 12F/16F/18F quick start

From DP

(Difference between revisions)
Jump to: navigation , search
m
m (Features)
 
(36 intermediate revisions not shown)
Line 1: Line 1:
==Features==
==Features==
 +
 +
* 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).
* 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 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.
+
* 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 ([http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805 PICkit 2], see eBay for clones) programs and debugs most PICs
+
* One inexpensive, cross-platform (Windows, Linux, Mac OS X) device (Microchip's [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805 PICkit 2], see eBay for clones) programs and debugs most PICs
* Previously famous for a generous sampling program (now dead)
* Previously famous for a generous sampling program (now dead)
 +
 +
{| border='1' class='wikitable'
 +
|-
 +
!        !!Baseline Architecture!!Mid-Range Architecture!!Enhanced Mid-Range Architecture!!PIC18 Architecture
 +
|-
 +
|| ''Families''      || align="center" |PIC 10, 12, 16  || align="center" |PIC 12, 16  || align="center" |PIC 12F1xxx, 16F1xxx  || align="center" |PIC 18
 +
|-
 +
|| ''Pin Count''      || align="center" |6-40            || align="center" |8-64        || align="center" |8-64                  || align="center" |18-100
 +
|-
 +
|| ''Interrupts''    || align="center" |No              || align="center" |Single      || align="center" |Single - hardware context save || align="center" |Multiple -  hardware context save
 +
|-
 +
|| ''Performance''    || align="center" |5 MIPS (20MHz)  || align="center" |5 MIPS (20MHz)  || align="center" |8 MIPS (32MHz)              || align="center" |up to 16 MIPS (48MHz)
 +
|-
 +
|| ''Instructions''  || align="center" |33, 12 bit      || align="center" |35, 14 bit  || align="center" |49, 14 bit            || align="center" |83, 16 bit
 +
|-
 +
|| ''Program Memory'' || align="center" |up to 3Kb      || align="center" |up to 14Kb  || align="center" |up to 28Kb            || align="center" |up to 128Kb
 +
|-
 +
|| ''Data Memory''    || align="center" |up to 134b      || align="center" |up to 368b  || align="center" |up to 1.5Kb          || align="center" |up to 4Kb
 +
|-
 +
|| ''Hardware Stack'' || align="center" |2 level        || align="center" |8 level      || align="center" |16 level              || align="center" |32 level
 +
|-
 +
|| ''Features''      || align="center" |comparator, 8 bit ADC, data memory, internal oscillator  || align="center" |baseline plus: SPI/I2C, UART, PWMs, LCD, 10 bit ADC, Op Amp  || align="center" |mid-range plus: multiple comms peripherals, linear program space, PWMs with independant time base || align="center" |enhanced mid-range plus: 8x8 hardware multiplier, CAN, CTMU, USB, Ethernet, 12 bit ADC
 +
|-
 +
|| ''Highlights''    || align="center" |lowest cost, smallest form factor || align="center" |optimal cost to performance ratio || align="center" |cost effective, more performance and memory || align="center" |high performance, optimised for C programming, advanced peripherals
 +
|}
===Reference===
===Reference===
* [http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en023805&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805# PICkit 2 Programmer User Guide]
* [http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en023805&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805# PICkit 2 Programmer User Guide]
-
 
* [http://ww1.microchip.com/downloads/en/devicedoc/33023a.pdf PIC mid range manual (16F)]
* [http://ww1.microchip.com/downloads/en/devicedoc/33023a.pdf PIC mid range manual (16F)]
-
 
* [http://ww1.microchip.com/downloads/en/DeviceDoc/39500a.pdf PIC 18F manual]
* [http://ww1.microchip.com/downloads/en/DeviceDoc/39500a.pdf PIC 18F manual]
-
 
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2575 PIC 24F manual]
 
-
 
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2573 dsPIC 33F manual]
 
==Development and programming==
==Development and programming==
Line 25: Line 48:
===IDE and compilers===
===IDE and compilers===
-
* Microchip's [http://en.wikipedia.org/wiki/Integrated_development_environment IDE] called [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 MPLAB]
+
* Microchip's [http://en.wikipedia.org/wiki/Integrated_development_environment IDE] called [http://www.microchip.com/mplab MPLAB]
* [http://devupdates.microchip.com/mplab/Files/installer.html MPLAB X] is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac OS X.
* [http://devupdates.microchip.com/mplab/Files/installer.html MPLAB X] is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac OS X.
* [http://www.microchip.com/C18 Microchip's C18 Compiler for PIC 18F]
* [http://www.microchip.com/C18 Microchip's C18 Compiler for PIC 18F]
-
 
-
* [http://www.microchip.com/C30 Microchip's C30 Compiler for PIC 24F/33F]
 
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.
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: [[#Resources|See Resources]] below.
+
There are many third-party compilers covering C, BASIC, Forth, JAL and Pascal: see [[PIC_Resources#Third_Party_Compilers|PIC Resources:Third Party Compilers]] for a list.
===Programmers===
===Programmers===
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805 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 [http://sites.google.com/site/pk2devicefileeditor/ 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.
+
There are many PIC programmers and debuggers, including some that you can build yourself. See [[PIC_Resources#Programmers|PIC Resources:Programmers]] for a brief description of the most commonly used.
-
 
+
-
* '''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!).
+
-
 
+
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en538340 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.
+
-
 
+
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046&part=DV164005 ICD 2] Superseded by the newer, cheaper ICD 3 (see below). Avoid.
+
-
 
+
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en537580 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 programmer====
+
-
 
+
-
* [http://www.mcuhobby.com/articles.php?article_id=7 PICkit 2 clone]
+
-
* [http://www.icd2clone.com/wiki/Main_Page ICD 2 clone]
+
-
* [http://www.edaboard.com/thread71480.html ICD 2 clone on a breadboard]
+
===Bootloaders===
===Bootloaders===
Line 71: Line 78:
===Power===
===Power===
-
 
+
*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
*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
*Put a 0.1uF decoupling capacitor on each positive supply pin, and put it as close to the chip on your PCB as possible
-
*Most 3.3volt PIC 18FJ/24FJ/33FJ have an internal 2.5volt regulator for the processor core. The regulator usually requires a 10uF tantalum capacitor on the VDDcore/VDDcap pin. Some PICs also have a VDDcore enable pin that must be tied high or low (differs by chip!) to enable the internal regulator.
 
===Reset===
===Reset===
-
[[image:quick-pic-reset.png]]
+
[[image:quick-pic18F-reset.png|250px]]
*Reset is the MCLR/VPP pin on PICs (MCLR=master clear, VPP=programming voltage)
*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, use 2Kohms for PIC 24/30/33
+
*Connect a resistor from MCLR to the supply voltage for normal operation, use 10Kohms for PIC 12/16/18
-
*PIC 12F/16F/18F - The programmer uses 12-13volts on MCLR to put the PIC 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
+
*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
-
*PIC 24F/30F/33F - The programmer holds MCLR low and enters a special key code key to start programming mode. No high voltage is used, no protection diode is needed.
+
===Programming connections===
===Programming connections===
Line 113: Line 118:
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).
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).
-
*18F - PORTA-D usually source/sink 25mA, others sometimes less
+
*PORTA-D usually source/sink 25mA
-
*18FJ - PORTA 4mA,PORTB-C 25mA
+
*Others sometimes less
-
*24FJ - All PORTs 18mA-25mA
+
-
*33F - Varies
+
===USB===
===USB===
[[image:quick-pic-usb-18F.png|490px]]
[[image:quick-pic-usb-18F.png|490px]]
-
*18F USB devices (5volt 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
+
*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
-
[[image:quick-pic-usb-18FJ.png|490px]]
+
*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)
-
*18FJ, 24FJ USB PICs (3.3volt parts) - No internal regulator. Requires an external 3.3volt supply to the VUSB pin, and 0.1uF decoupling capacitor
+
*All PIC USB peripherals have internal resistors, no other support circuitry is required
-
*All PIC USB peripherals have an internal resistors, no other support circuitry is required.
+
-
 
+
-
===Ethernet===
+
-
 
+
-
[[image:quick-pic-ethernet.png|490px]]
+
-
 
+
-
There are a few PICs with integrated Ethernet MAC/PHYs. They generally require the same interface circuit as the ENC28J60, and many Ethernet PHYs.
+
-
*49.9ohm 1% resistors are important to stay within the Ethernet spec
+
-
*The ferrite bead (L1) is any simple ferrite bead, the exact value doesn't usually matter
+
-
*Ethernet jacks with integrated magnetics are a pain to choose, check the pinout because most are different
+
-
 
+
==Resources==
==Resources==
-
===Information===
+
See [[PIC Resources]] for more information, third party compilers, operating systems/kernels, hardware (development boards), other tutorials and online PIC programming books.
-
 
+
-
* [http://www.microchip.com Microchip website] for all things PIC (application notes, sample code, device datasheets, device errata, device reference guides, development board user manuals, board schematics and code etc).
+
-
* [http://forum.microchip.com/ Microchip Forums] cover microcontrollers, programmers, compilers etc.
+
-
* [http://www.piclist.com/techref/piclist/ The PIC Mailing List]
+
-
 
+
-
===Third Party Compilers===
+
-
 
+
-
* [http://www.casadeyork.com/jalv2/ 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 [http://www.voti.nl/jal/index.html Wouter van Ooijen], which is loosely based on Pascal. JAL compiles code for baseline, midrange and the 18F PIC series. Extensive [http://code.google.com/p/jallib/ libraries] are available for JAL and there is an IDE called [http://jal.sunish.net/jaledit JAL Edit]. The JALv2 is an open source cross platform compiler running under Windows, Linux, FreeBSD and Mac OS X.
+
-
 
+
-
* [http://gcbasic.sourceforge.net/ 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.
+
-
 
+
-
* [http://www.rfc1149.net/devel/picforth PicForth] is a Forth compiler written in gforth and hosted on Unix (or Linux) which generates code for the PIC 16F87x and 16F88 series. It includes two kinds of cooperative schedulers.
+
-
 
+
-
* [http://sdcc.sourceforge.net/ SDCC] is a retargettable, optimizing ANSI - C compiler that targets the Intel 8051, Maxim 80DS390, Zilog Z80 and the Motorola 68HC08 based MCUs. Work is in progress on supporting the Microchip PIC 16 and 18 series. SDCC is Free Open Source Software, distributed under GNU General Public License (GPL).
+
-
 
+
-
* [http://www.pmpcomp.fr/ PMP] (Pic Micro Pascal) is a free Pascal cross compiler for PIC™ processors. It is intended to work with the Microchip MPASM/MPLINK suite installed; it has its own IDE and it is a highly optimized compiler. It supports most devices from PIC 10 to 18.
+
-
 
+
-
* [http://www.mikroe.com/eng/categories/view/2/compilers/ Mikroelektronika] sells C, BASIC, and Pascal compilers for Windows with their own IDE for the Microchip PIC and dsPIC microcontroller series. These compilers have extensive function libraries. Code size limited demo versions are available for free download.
+
-
 
+
-
===Operating Systems, Kernels===
+
-
 
+
-
* [http://flashforth.sourceforge.net/ FlashForth] is a native Forth operating system for the PIC 18F and the dsPIC 30F series. It makes the PIC a standalone computer with an interpreter, compiler, assembler and multitasker.
+
-
 
+
-
* [http://www.freertos.org/ FreeRTOS] is a mini real time kernel ported to the PIC 24, dsPIC and PIC 32 series.
+
-
 
+
-
* [http://www.ucapps.de/mios.html/ MIOS] is a real-time operating system written in PIC assembly for the requirements of flexible MIDI applications like MIDI controllers, processors, synthesizers, sequencers. PIC 18F452, 18F4620 and 18F4685.
+
-
 
+
-
===Hardware===
+
-
 
+
-
* [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=81 Microchip] provides a comprehensive range of development boards and kits.
+
-
* [http://www.sureelectronics.net/search.php?encode=YTozOntzOjg6ImtleXdvcmRzIjtzOjg6InBpYyBkZW1vIjtzOjg6ImNhdGVnb3J5IjtzOjI6IjMyIjtzOjE4OiJzZWFyY2hfZW5jb2RlX3RpbWUiO2k6MTI5MDcyNTA1MDt9 Sure Electronics (China)] provide a range of cheap(er) development boards, PICkits and a useful universal PIC programming socket.
+
-
* [http://www.seeedstudio.com/depot/web-platform-v11-assembled-p-582.html Seeed Studio (China)] sells Dangerous Prototypes' very own [[Web Platform]] which is a great inexpensive dsPIC33 development board.
+
-
* [http://justanotherlanguage.org/content/jaluino Jaluino] is an open-source project aimed to provide Arduino-like boards based on the PIC 18 family and powered by [http://www.casadeyork.com/jalv2/ jalv2] and [http://code.google.com/p/jallib/ jallib]. Schematics, PCB Gerbers, tutorials, etc are all available.
+
-
 
+
-
===Books===
+
-
 
+
-
mikroElektronika rather generously makes the following books which it publishes (and sells in hard copy) available online for free:
+
-
* [http://www.mikroe.com/eng/products/view/285/book-pic-microcontrollers-programming-in-c/ PIC Microcontrollers - Programming in C]
 
-
* [http://www.mikroe.com/eng/products/view/476/pic-microcontrollers-programming-in-basic/ PIC Microcontrollers - Programming in Basic]
 
-
* [http://www.mikroe.com/eng/products/view/264/programming-dspic-mcu-in-pascal/ Programming dsPIC (Digital Signal Controllers) in PASCAL]
 
-
* [http://www.mikroe.com/eng/products/view/265/programming-dspic-mcu-in-basic/ Programming dsPIC (Digital Signal Controllers) in BASIC]
 
-
* [http://www.mikroe.com/eng/products/view/266/programming-dspic-mcu-in-c/ Programming dsPIC (Digital Signal Controllers) in C]
 
[[Category:Tutorials]]
[[Category:Tutorials]]
 +
[[Category:Processor Overviews]]
 +
[[Category:PICs]]

Latest revision as of 04:29, 12 February 2011

Contents

Features

  • 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 ArchitectureMid-Range ArchitectureEnhanced Mid-Range ArchitecturePIC18 Architecture
Families PIC 10, 12, 16 PIC 12, 16 PIC 12F1xxx, 16F1xxx PIC 18
Pin Count 6-40 8-64 8-64 18-100
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

Reference

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.

Programmers

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.

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

Quick-pic-basic.png

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).

Power

  • 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

Quick-pic18F-reset.png

  • 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

Programming connections

PICs use a 5 wire programming connection called ICSP in PIC datasheets. This is the prefered pinout order, it's compatible with the PICkit:

  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. PGD - Program data, a bi-directional data pin (often PORTB7)
  5. 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

Clock source

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).

Peripherals

IO

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

USB

Quick-pic-usb-18F.png

  • 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

Resources

See PIC Resources for more information, third party compilers, operating systems/kernels, hardware (development boards), other tutorials and online PIC programming books.