let’s be realistic. We are
programming a microcontroller that
does not have a computer screen
associated with it, so we are limited
initially with the Experimenter digital
I/O. Fortunately, some of the I/O is
connected to its onboard LEDs. In
other parts of this series, we will
show the use of USB to write to the
computer screen, but for now we
will use LEDs. To make our “Hello
World” meaningful, we will start
with the onboard LEDs and then
advance to a 5x7 LED matrix for
more exciting light shows that
demonstrate the use of the RTOS
and the PIC32 DMA controller.
Here’s the run-down:
• Demo 1: Blinky LEDs —
alternate blinking onboard LEDS ( BLINKY.MCP
• Demo 2: Turn on the LED with a pushbutton
( PUSHBTN.MCP source).
• Demo 3: RTOS individual LED control ( RTOS.MCP
• Demo 4: DMA transfer to LED ( DMA.MCP source).
continuous loop using a toggle function and a software
delay for blink.
Demo 2 “Hello World” —
The particular 5x7 matrix for Demos 3 and 4 is shown
in Figure 6, along with the hook-up diagram in Figure 7.
Let’s start working through the different experiments.
Demo 1 “Hello World” —
This demo is similar in structure to Demo 1, but
responds to either of the two Experimenter pushbuttons
being depressed by lighting the corresponding LED
associated with the button. This code is shown in Figure 9.
The project is located in the PUSHBUTTON folder.
Demo 3 “Hello World” —
Using an RTOS
The first demo is found in the Blinky folder, so open
that folder and double-click on BLINKY.MCP. This should
invoke MPLAB and bring up the
Blinky project. Select your
the project, and download the
code to the Experimenter with
hooked to ICSP. You should see
the two LEDs on the Experimenter
Let’s examine the code. All
these programs use #include
<plib.h> to reference the PIC32
library and part. We then set the
fuses for 80 MHz operation and
the peripheral bus to 40 MHz.
Then, we invoke a library function
PIC32 operation. This function
sets pre-fetch cache, RAM, and
Flash wait states for the 80 MHz
clock. Finally, we configure the
digital I/O for LEDs and enter a
An RTOS for microcontrollers is similar to operating
FIGURE 9. Pushbutton code.
February 2011 61