PIC 18FJ/24FJ/33FJ quick start
- 18FJ - 8bits, 48MHz (10 to 12 MIPS), 2 to 3.6 volts
- 24FJ - 16bits, 32MHz (16 MIPS), 2 or 2.2 to 3.6 volts
- 33FJ - 16bits, 80MHz (40 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
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. Our 18FJ port is available from the Logic Sniffer SVN.
This is the most basic circuit required to program a PIC 18F2550. Most PICs require a similar minimum support circuit.
- 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 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.
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).
- 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
- 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.
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
See PIC Resources for more information, third party compilers, operating systems/kernels, hardware (development boards), other tutorials and online PIC programming books.