PIC 18FJ/24FJ/33FJ quick start

From DP

Jump to: navigation , search

Contents

Features

  • 18FJ - 8bits, up to 64MHz (10 to 16 MIPS), 2 to 3.6 volts
  • 24FJ, 24E - 16bits, 32MHz (16 to 70 MIPS), 2 to 3.6 volts
  • 33FJ, 33E - 16bits, 80MHz (40 to 70 MIPS), 3 to 3.6 volts
  • Many parts still in though-hole packages
  • One inexpensive, cross-platform (Windows, Linux, Mac OS X) device (Microchip's PICkit 2, see eBay for clones) programs and debugs most PICs

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-circuit.png

This is the most basic circuit required to program a PIC 18F2550. Most PICs require a similar minimum support circuit.

Power

Quick-pic-vddcore.png

  • PIC 18FJ/24F/33F run at 3.3volts, and lower voltages but at reduced speeds
  • 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
  • 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

Quick-pic18FJ-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 2Kohms for PIC 18FH/24FJ/33FJ
  • The programmer holds MCLR low and enters a special key code key to start programming mode for PIC 24F/30F/33F. No high voltage is used, no protection diode is needed as on the 12F/16F/18F.

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

  • 18FJ - PORTA 4mA,PORTB-C 25mA
  • 24FJ - All PORTs 18mA-25mA
  • 33F - Varies, most are 4mA

Peripheral pin select

This is a fantastic feature that lets you assign certain hardware modules (UART, SPI, PWM, timers, interrupts, etc) to any RPx pin. This makes routing super flexible, like a CPLD or FPGA.

  • Outputs: assign a pin number to a module output register
  • Inputs: assign a module number to an input pin register

USB

Quick-pic-usb-18FJ.png

  • 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
  • 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 an internal resistors, no other support circuitry is required.

Ethernet

Quick-pic-ethernet.png

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

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