This example project detects a button press to enable and disable a blinking LED. A push button switch on the evaluation board is connected to an I/O Port pin on the PIC32. This I/O Port pin is configured to use its Change Notification feature. This feature generates an interrupt any time a change of state is detected on the pin.
When a button press is detected, a System Timer Object is created. This timer object creates a delay used to debounce the switch and blink the LED. Once a press is confirmed (switch debounced), the LED will start or stop blinking.
When a button press to stop the blinking LED is detected, the LED is shut off. The System Timer Object created when the button press was first detected is then deleted to conserve system resources. The PIC32 will remain in this idle state until another button press is detected, at which point a new System Timer Object will be created.
The code you will add to this example project (as described in the following steps) implements the state machine shown in the diagram below.
You may also be interested in another example project that shows how to blink LEDs at a constant rate:
Learn more >
The "Project and Source Files" download (see below) contains a fully functional project. It can be used as an example and requires no modifications. To gain a deeper understanding of how to use the MPLAB® Harmony framework, we recommend you generate the project and source files yourself by following the step-by-step procedure below.
|Tool|| About|| Purchase|
This project has been verified to work with the following versions of software tools:
MPLAB® X IDE v3.25, MPLAB® XC32 Compiler v1.40, MPLAB® Harmony v1.07.01
Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double check using the same versions that the project was tested with.
Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
Note that multiple versions of all these tools can co-exist on the same computer.
| Windows|| Linux|| Mac OSX|
Integrated Development Environment
MPLAB® Harmony 1.xx
Integrated Software Framework
The contents of the following zip file need to be placed in this directory. If this is not done, the MPLAB® X IDE will not be able to find all source files, and the project will not build successfully.
<Harmony install path>/apps/training
(example Harmony install path = c:/microchip/harmony/v1_07_01)
| Windows|| Linux|| Mac OSX|
Project and Source Files
The "Project and Source Files" download provides a fully functional project. It can be used as an example and requires no modifications. The following steps below provide instruction on how this project was created.
Create a new MPLAB® Harmony project
The Target Device used on the chipKIT™ Wi-FIRE is the PIC32MZ2048EFG100.
Use the BSP to load appropriate default values for the PIC32 core, clocks, and I/O port pins.
Use MHC to enable the Ports System Service and I/O Port Change Notification feature.
Use MHC to enable and configure the Timer System Service
Use MHC to generate the code
Add application states and variables to your project in app.h
Add application-specific configuration constants to the project in system_config.h.
Modify the interrupt service routine for the I/O Port Change Notice feature.
Create the callback function used by the Timer Driver (called by Timer ISR).
Create the callback function called by the I/O Port Change Notice ISR.
Create the application initialization function.
Add application code to your project:
- Create a 50 ms delay using the Timer System Service
- Create a state machine to debounce the switch, blink the LED, and enable and disable the Blinking LED.
Connect the development board and programmer/debugger to your computer, then select the XC32 compiler version and programmer/debugger for the project
Build, program and run your projectClick the "Run" icon to build, program and run your project.
After successfully programming the device, the LED will start blinking. Press Switch 1 on the board to stop the blinking. Press it again to restart the blinking.
This example project demonstrates much more than configuring, monitoring, and controlling PIC32 I/O Port pins. You've also learned the basic program architecture common to all MPLAB Harmony projects.
You may be thinking that this a lot of code to monitor a switch and blink an LED. This is true. An 8-bit device can perform this task for less cost and less code. The assumption is you will want to integrate this code into a larger project that may already implement the Timer System Service (e.g. the Harmony TCP/IP stack). This code will work cooperatively with other Harmony library modules, and it will efficiently share PIC32 resources. It can also be easily reused in other PIC32 projects.