0: Getting Started

The PIC32 is a family of super powerful and super cheap 32-bit microcontrollers. Note that with the extra power of 32-bits over the popular and simple 8-bit microcontrollers comes an increased complexity. That’s why we’re here to help!

A number of development boards exist to make programming your PIC32 much simpler. These tutorials are mostly geared towards working with Brian Shmalz’s UBW32 and Dan Overholt’s CUI32 but the the majority of info is valid for any PIC32 (with some exceptions for 1xx/2xx families) and development board.

The tutorial’s were designed as .c files that contain highly descriptive comments followed by the code itself with even more comments. These .c files are downloadable at the bottom of each tutorial page. This tutorial also has a bunch of extra useful files at the pages top.

Note that tutorial 0 is geared towards Windows systems using MPlab (probably version 8). MPlab X betta was recently released and works with Linux and Mac systems. We’ll be fiddling with that very shortly but for now we only have Windows specific info.

Feel free to modify the code and use it for your own projects! If you do, we would love to hear what you’re working on and possibly collaborate!  Shoot emails to umassamherstm5 (at) gmail.com.

Useful Files

  • procdefs.ld
    • Linker script to define memory regions on development boards that use USB
    • Will download as “procdefs.ld.txt” but make sure to save as “procdefs.ld”
  • HIDBootLoader
    • The application to load hex files onto the CUI32 / UBW32
  • Peripheral Library Guide
    • Reference doc of library functions you can use with MPLab
  • UBW32 MX795 schematic
    • UBW32 Schematic



Tutorial 0 – Getting Started

last updated 9-21-11
written by Rodrigo Bismonte and Sean Klaiber
screenshots taken by Rodrigo Bismonte

Download and install MPLAB IDE (probably v8).
Download Microchip HIDBootLoader.exe
Download the needed linker file named “procdefs.ld”
– both files are contained within this tutorial

For organization, it’s recommended to make a new directory (anywhere) to save your MPlab project files to. MPlab will not do this for you. It’s also recommended to place procdefs.ld in this new directory.

Open Microchip MPLAB IDE.

Click Project > Project Wizard (picture1)

This will open the Project Wizard Dialog. Press next. (picture2)
Select your particular microprocessor from the list.
The UBW32 at the time of writing this tutorial uses the PIC32MX795F512L. Press next.
The CUI32 at the time of writing this tutorial uses the PIC32MX440F512H. Press next. (picture3)

Next, we are prompted for which compiler to use. On Active Toolsuite, select “Microchip PIC32 C-Compiler Toolsuite”. (picture4) Then, under “Toolsuite Contents”, select “MPLAB C32 Compiler (pic32-gcc.exe) v1.10” (picture5) and press next.

Then, create the project file (.mcp) for your project in your hard drive. In this case, it is in “J:\PIC32\MPLab Projects\tutorial0\tutorial0”. (picture6) Press next.

Now, add the needed files to the project. You should ALWAYS include the procdefs.ld in all your projects written for the CUI32/UBW32 in order to prevent you from bricking your board. Since this is a blank project, procdefs.ld is the only file we are adding. Make sure to place procdefs.ld in the directory you are using and not just add it to the project! (picture7)

Note that if procdefs.ld is added to the project through MPLAB but not directly added to the directory, the lights will continue to flash on the UBW32 and the board will be effectively “bricked”.

Click Next, then click Finish.

On the tutorial0.mcw window, drag procdefs.ld into the folder called “Other Files”. (picture 8 shows before and after)
If you don’t do this, you will probably “brick” the UBW32/CUI32 making it unusable!! It can be debricked only with a Microchip programmer like the PicKit 3 (~$45). YOU HAVE BEEN WARNED!!

Now, go to File > Add New File to Project… (picture9)
Name your .c file the name of your program. In this case, I called mine “main.c”. (picture10)

You should end up with main.c under the “Source Files” folder in your project manager window, and a blank main.c screen. (picture11)

After writing your program, save your .c file (File > Save) and save your workspace (Project > Save Project).

***NOTE: For your program to compile properly, you must add a newline at the end of your code (press Enter after the last line). ***

To program your PIC32, you need to create the .hex file by pressing the “Make” button or going to Project > Make or pressing F10. After this, the output screen should say “BUILD SUCCEEDED”. (picture 12)

Plug in your CUI32 or UBW32 to your computer and run HIDBootLoader.exe. On the CUI32 or UBW32, press and hold both the PROG and RESET buttons. Then, release the RESET button first, followed by the PROG button. Colored status LED’s should now be flashing rapidly, indicating that the CUI32 or UBW32 is ready to be programmed. The HIDBootLoader program should also say “Device attached”. (picture13).

Now, press “Open Hex File”, and navigate to your project folder. Select the .hex file that belongs to your program, and press Open. In this case, the file is called tutorial0.hex. (picture14)

Finally, press “Program/Verify” to upload your code to your CUI32/UBW32. Then, you can either press “Reset Device” in the HIDBootloader program or physically press the RESET button on your CUI32/UBW32.

Congratulations! You have now programmed your PIC32.


PIC32 Tutorial 0 Getting Started

2 thoughts on “0: Getting Started

  1. The UBW32 website states NOT to add the procdefs.ld file to the project(see below), just make sure the file is in the project folder. I’m guessing your step that moves it from the linker folder to the other files folder is getting around the problem but you may want to remove that step.

    UBW32 Linker file and the HID Bootloader (For UBW32 projects only)

    You must be sure to have the procdefs.ld file in your project folder when you build your firmware application for the UBW32 if you are going to download it using the HID Bootloader (which is the standard way for download programs into the UBW32). This file, if present (and named exactly that) will tell the C32 linker to reserve the proper space for the HID bootloader in the resulting HEX file. This file is contained in each of the UBW32 project folders that is on this website. HOWEVER- you must never add the procdefs.ld file to your actual MPLAB project (i.e. don’t add it to the Linker folder inside MPLAB). Doing this will result in a HEX file that won’t run.

  2. In the upper left corner of
    it says MX460, but in the lower right corner (legend) it says MX795, which is also contained in the URL.

    I got there from a link on 0: Getting Started under the heading “Useful Files”.

    I assume 795 is correct and the 795 schematic was created by revising the 460 schematic and the 460 remains as a failure to change it to 795 in the revision. Is this correct?

Leave a Reply

Your email address will not be published. Required fields are marked *