FIGURE 9. Custom 'C' library and associated API.
FIGURE 10. MPLAB X main tool bar icon description.
FIGURE 11. MPLAB 8 to MPLAB X debugger icon comparison.
The demos also use a number of ‘C’ custom library
functions, as well as the standard PIC32 reference library.
A pictorial of the custom library collection is shown in
Figure 9. Each demo uses a combination of these library
elements. The unique code for each demo is really carried
out in “Main.”
The custom libraries are pretty self-explanatory. The
50 July 2012
ADC library handles initializing the 10-bit ADC in the
PIC32 for one of its 13 channels, and then collects
sampled data from that channel. The LCD library allows
for initializing of the LCD, clearing the display, setting the
cursor position, and writing to the display.
The DELAY library provides for a number of software-based delays that are used through the library and in
Main. The BUTTON library handles initializing digital input
for four buttons, and then debouncing and reading button
Demo software is provided in the form of three
MPLAB X projects, as described below.
1. BUTTONDEMO (LCD and buttons): This is a basic
demo that starts with a splash display highlighting the new
PIC32 part and its capabilities. It then prompts the user to
push a button and then displays which button was
pressed. Uses LCD, Delay, and Button libraries.
2. ADCDEMO (ADC operation): This is a demo of
the PIC32MX2 10-bit ADC using the ADC library. A 10K
potentiometer is required to be wired up with wipers
connected to pin 10 of the Experimenter J3 expansion I/O
connector (see the board silkscreen in the downloads for
actual pin position). The other two ends of the
potentiometer are wired to + 3. 3 VDC and ground from
the Experimenter (again, see the board silkscreen for
+ 3.3V and ground output pins). The display will
automatically update the ADC count and ADC voltage as
the potentiometer position changes. Uses ADC, LCD, and
3. PWMDEMO (LED dimmer operation): This demo
uses the ADC and the PWM output from the Output
Compare module 2 (OC2) to control brightness to an
LED. A potentiometer is hooked up to the Experimenter as
in #2 above. In addition, OC2 is configured using PPS for
pin 5 of J3 (see the board silkscreen for actual pin
position). Also on pin 5 J3, a 470 ohm resistor in series
with an LED anode (with the cathode to ground) is
needed. As you rotate the pot, the PWM to the LED
changes duty cycle from 100%-0%, thereby affecting its
brightness. The Main code illustrates the use of the
Programmable Peripheral System (PPS) feature of this
device by allowing a user to configure a programmable
pin with a peripheral output. In this case, RB8 is
configured for an OC2 peripheral. Use of the PIC32
peripheral library for selecting OC2 under PPS and
enabling it (as well as setting pulse width for PWM) is
demonstrated here. The project also uses ADC, LCD, and
Using MPLAB X
MPLAB X is new and there are a lot of features — way
too many to cover here. So, since pictures are worth a