Getting started

To prepare and test your system for use with the programs in this library collection, perform the following steps:

    1. Software installation - Install the necessary software on a Windows-based PC. All the necessary software is free.
    2. Hardware bring-up - Build or purchase a PIC24-based board.
    3. Programming and communication - Flash your PIC24 with the bootloader, then connect it via a serial link to your PC.
    4. Test the PIC - Using the bootloader, program the PIC with the echo program and test. This verifies proper installation of your hardware/software setup.

After this, view a wide range of videos to use your working system in a number of practical ways.

Software installation

    1. Download and install the latest version of the MPLAB X IDE.
    2. Download and install the latest version of the MPLAB XC16 compiler. Notes:
      1. MPLAB must be installed before the compiler
      2. Accept all the defaults when installing; in particular, click "Yes" to the "Modify Environment?" question. No new program will show up on your start menu; instead, the compiler will now be available in MPLAB. That enables the compiler to properly register itself with MPLAB.
    3. If you do not have the Microsoft .NET framework installed, download and install the .NET runtime by visiting the Microsoft Download Center and searching for '.NET runtime'. Install version 2.0 or later. If you're not sure if the .NET framework is installed, try running the bootloader in the following step; if it fails, download the .NET framework.
    4. Download and unzip the latest version of the PIC24 library collection. Notes:
      1. We recommend installing to a directory without spaces; on pre-Vista windows, installing on the desktop violates this rule, since the desktop directory is "C:\Documents and settings\...".
      2. Test the bootloader, a .NET application, by executing bin\winbootldr.exe. A GUI should pop up. If that fails, consult the bootloader documentation for troubleshooting steps.

Hardware bring-up

There are several options for acquiring the hardware necessary to run a PIC24:

Wiring up a PIC24

    1. Begin by following the prototyping walk-through, also available as a video.
    2. Using an ICSP programmer, program the bootloader onto your PIC.
    3. Install the FTDI drivers (use the setup executable link) to communicate with your PIC via an FTDI cable.

SparkFun PIC24 breakout board

Obtain a SparkFun PIC24 breakout board (this product is no longer in production). This comes with bootloader firmware already installed as well as the 'reset.c' application (code/chap8/reset.mcp) with the bootloader's baudrate set to 57600. Then, watch the video or read instructions on using it. The brief version:

    1. At a minimum, install 0.1" pitch headers in the 6-pin connection for use with an FTDI cable. Installing headers in the remaining positions allows access to much of the functionality of the chip.
    2. Install the FTDI drivers (use the setup executable link) to communicate with your PIC via an FTDI cable.
    3. For advanced users, purchase a SparkFun ICSP connector for use with an ICSP programmer.

Explorer 16 board

The Explorer 16 is a development board available from Microchip - it comes in 100 pin and 44 pin versions. This video discusses its use with the library. The CPU is set by a plug-in module, of which each board has a few available. The directory code/explorer16_100p contains a few examples for the Explorer16/100 pin board. These projects can use the source files from the other directories, but the macro HARDWARE_PLATFORM=EXPLORER16_100P either must defined in the include/pic24_all.h file or it must be added to the MPLAB project (Use Project->Build Options-> Project, click on the MPLAB C30 tab, and in Macro Definitions click 'Add', and add EXPLORER16_100P). The HARDWARE_PLATFORM=EXPLORER16_100P macro causes the default UART to be UART2 since that is what is used on the Explorer16/100 pin board. It also causes the clock option to use the external 8 MHz oscillator, with the PLL used to produce a 16 MHz FCY for PIC24F devices and 40 MHz FCY for the PIC24H.

Microchip Microstick

The Microchip Microstick is a new low-cost platform for PIC24 and dsPIC33 experimentation. It is a breakout board for 28-pin devices that offers on-board debugging and in-circuit programming (like a PICkit). The board plugs into a breadboard, with access to all pins for maximum versatility. This page shows how to use the Microchip Microstick with the book examples. To use this with the projects in the library:

1. In MPLAB X, open the project

2. Open project properties

Change the device based on what you installed in your board -- the PIC24HJ128GP502, for example.

Select the Microstick II Hardware Tool

Select the XC16 Compiler Toolchain

Under category XC16 (Global Options)

Define common macros - double click to add HARDWARE_PLATFORM=5.

Apply - OK

3. Remove the linker file from project

The Dangerous Prototypes web server

The library provides support for the Dangerous Prototypes web server, by defining HARDWARE_PLATFORM=DANGEROUS_WEB. See the instructions above for the Explorer 16 board on how to incorporate this in to the library.

The Microchip 16-bit 28-pin Starter Board

The library provides support for the Microchip 16-bit 28-pin Starter Board, by defining HARDWARE_PLATFORM=STARTER_BOARD_28P. See the instructions above for the Explorer 16 board on how to incorporate this in to the library. Thanks to István (icserny at gmail dot com) for contributing this code!

Programming and communication

ICSP programmers

If you purchase an unprogrammed PIC24 chip, you'll need to program it with the bootloader, after which the bootloader can be used to program the PIC24 with your code. If the bootloader gets corrupted, it must be reprogrammed. Finally, advanced users may which to remove the bootloader and program the PIC24 via ICSP. Several options exist:

    • Microchip sells the PICkit3 low-cost programmer; only the PICkit3, not the various starter kits, are required. This video discusses using the PICkit2 with PIC24 CPUs.
    • A second, more expensive option is the Microchip ICD2.
    • Third-party programmers can (possibly) be used.

To program your PIC with the bootloader using a PICkit3:

    1. Use the MPLAB IPE program which comes with the MPLAB X IDE.
    2. Connect the PICkit 3 programmer up to your board. The arrow on the PICkit corresponds to pin 1.
        • The PICkit may need to have an OS downloaded. If the PICkit software complains, click Tools -> Download PICkit 2 Operating System.
    3. In MPLAB IDE Device drop-down, select the specific chip you're programming.
    4. Load on the bootloader via File -> Import Hex. Be sure to select the appropriate PIC architecture..

FTDI cable

A simple solution for connecting your PIC24 to a PIC is an FTDI TTL-232R-3V3 USB to TTL level serial converter cable. One end plugs into a PC's USB port while the other provides TTL-compatible serial I/O lines which can be directly connected to your PIC's serial I/O pins. In addition, the cable provide +5V, which can be used to power your board through a regulator. For more information, see the FTDI datasheet. Sources:

    • Digi-key, Mouser, etc.
    • SparkFun sells their own FTDI board, which provides the same functionality as the cable.

Testing with echo

With the necessary software installed and hardware acquired, test your system by programming it with a simple echo program. The echo program waits for a UART1 RX character, increments it, then echos it back. To test:

    1. Before programming the PIC with the echo program, be sure to have all the required software installed and the bootloader loaded (see the steps above).
    2. Open MPLAB, then open the echo project using Project -> Open.
    3. The project should compile as is; build the project with Run -> Build project.
    4. Start the PIC24 bootloader after downloading it. Or, start the old PIC24 bootloader application by opening bin/winbootloader.exe.
    5. Hook the USB cable up to your computer and to your PIC.
    6. In Bully Bootloader, select the appropriate COM port and baud rate and check "OpenCOM."
      1. The baud rate is determined by the bootloader firmware loaded on the target PIC24 micro (the default baudrate is 230,400 for all devices but the PIC24F/FK, where is it 57,600).
      2. If you do not know which COM port to use, in Windows select Start -> Control Panel -> System (or Windows Key + Pause|Break). Select the Hardware tab and click Device Manager. In the new window, expand the "Ports (COM & LPT)" entry and look for "USB Serial Port (COMx)".
    7. Click the HexFile button and navigate within the Open dialog box to your MPLAB's project directory\dist\default\production and select <project name>.production.hex.
    8. Select the appropriate .hex file, and click Open.
    9. Press and hold the MCLR button on your PIC24. Immediately after you release the MCLR button, click the Program button in the Bully bootloader. You should see the lower output box scrolling with information.
    10. At the top of Bully bootloader is a white text input field. Type the letter 'a' into the box, and click Send.
    11. Check to see that the letter 'b' appeared in the top output box, just below the input text field. More bootloader documentation is found at Bully Bootloader GUI documentation.

Other terminal emulators

Several other terminal emulations enable you to communicate with your PIC24, though they do not provide the ability to program it; you must instead use an external programmer, such as the PICKit 3. These emulations offer additional features (scripting, data logging, etc.). A few examples:

For more options, see a list of terminal emulators. The only consideration for using a serial program with the code examples accompanying this web site is that our console output functions use a single “\n” (new line) character to mark end-of-lines, and some programs, such as PuTTY, expect a “\n\r” (new line, carriage return) sequence. The behavior of library console output functions can be changed, but this requires editing a header file (see the "outString() end-of-line behavior in pic24_serial.h" section in pic24_libconfig.h). RealTerm and Tera Term can be configured for different types of line endings.

The figure below shows the steps necessary for configuring RealTerm for serial communication under the Windows operating system. The first step chooses the display mode, subfigure (a) selecting the ANSI text mode and a “\n” (new line) character as the end-of-line marker. The second step subfigure (b) chooses the serial port parameters, such as the COMx port used for communication, speed, and data format. COM ports are assigned numbers 1 and higher, so valid COM port names are COM1, COM2, COM3, etc. The Device Manager found within "System and Maintenance" in the Control Panel under Windows can be used to identify COM ports assigned to connected USB serial port devices as shown in subfigure (c). The default serial port parameters used by this library are a baud rate of 230,400 for all but PIC24F/FK devices which use 57,600 baurd, 8 data bits, 1 stop bit, no parity, and no hardware flow control. Serial communication is discussed in more detail in Chapter 10 of the textbook.

Hardware Debugging Tools

An extremely useful hardware debugging tool is a USB logic analyzer.