Beginner Lab 6: Switch Input via GPIO

Last modified by Microchip on 2026/06/26 07:36

Objective

  1. Set up a General-Purpose Input/Output (GPIO) pin to detect the state (pressed or released) of a mechanical push button (SW1).
  2. Configure another GPIO pin to drive an LED, turning it ON or OFF based on the input received from the switch.
  3. Write and test embedded C code to continuously monitor the switch and update the LED state in real time.
  4. Understand the importance of pull-up or pull-down resistors in reliable input detection.
  5. Enable Debouncing to avoid multiple transitions when the mechanical button is pressed or released.
  6. Observe the practical application of digital logic in embedded systems by integrating hardware and software components.

Overview

This lab exercise introduces the fundamental principles of GPIO in embedded systems. The experiment involves configuring a mechanical switch (SW1) and an LED (LED1) on the PIC32CM LS00 Curiosity Nano+ Touch Evaluation Kit. The state of the switch (ON/OFF) is detected and indicated by controlling the LED, thereby providing visual feedback of the input signal. The exercise also includes the implementation of debouncing techniques to ensure reliable and accurate detection of signals from mechanical buttons.

Lab Activities

  • Identify the GPIO pins connected to the switch (SW1) and the LED using the specified board user guide.
  • Configure the External Interrupt Controller (EIC) peripheral and assign the appropriate EIC pin for SW1 in MPLAB® X IDE.
  • Set up the GPIO pin for the LED using the pin configuration tool.
  • Add application code to the generated project, implementing the necessary interrupt handlers and callback functions for EIC interrupt generation and LED toggling.
  • Observe the output by verifying the toggling of the LED on the PIC32CM LS00 Curiosity Nano+ Touch Evaluation Kit.

Expected Outcomes

Upon completing this lab, you will be able to:

  • Successfully configure the EIC and assign the correct EIC pin for SW1 in MPLAB X IDE.
  • Set up and configure GPIO pins for output devices such as LEDs.
  • Develop and integrate application code to implement interrupt handlers and callback functions for EIC interrupt generation and LED toggling.
  • Verify the correct operation of the system by observing the toggling of the LED on the PIC32CM LS00 Curiosity Nano+ Touch Evaluation Kit.

Lab Source Files and Solutions

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the lab as per the following step-by-step instructions (see the "Lab Index" section on this page).

Download the ZIP file for this lab.

Information

The contents of this ZIP file need to be placed in the following folder:

<Any directory of user's choice>/
(example Directory = C:/microchip/harmony/v3)

Note:

  1. The project location of an MPLAB  Harmony v3 project is independent of the location of the MPLAB Harmony framework path (in other words,  there is no requirement to create or place an MPLAB Harmony v3 project in a relative path under the Harmony v3 framework folder). The project can be created or placed in any directory of your choice.
  2. The point above is true because when created, an MPLAB Harmony v3 project generates all the referred source and header files and libraries (if any) under the project folder.

Lab Index

Back to Top