Tiva Lab 02: Using GPIO to Control LED


  • Understand I/O operation in Tiva TM4C LaunchPads
  • Get acquainted with using on-board RGB/LEDs and User Switches
  • Learn the steps of GPIO configuration on Tiva TM4C LaunchPads
  • Learn how to read a data from input pin, and write a data to output pin
  • Learn how to design a delay function by using software loops

Required Reading Material

Background Information

GPIOs are the basic interfaces of any microcontroller. For a positive logical system, a GPIO pin can be set high (taking the value 1) by connecting it to a voltage supply, or set low (taking the value 0) by connecting it ti ground. The Tiva LaunchPad can set the GPIO pin to take either value and treat it as an output, or it can detect the value of the pin and treat it as an input.

You will learn how to write an assembly or C code to configure the GPIO ports, read the status of switches and turn on/off the LEDs.


Required Components List

  • Tiva EK-TM4C123GXL LaunchPad Kit EK TM4C123GXL s or EK-TM4C1294XL LaunchPad Kit TM4C1294XL s.
  • The switchese and LEDs on the Tiva LaunchPads board will be used in this lab.


Circuit / Schematic Diagram

You have to know the location of LEDs and switches on the TI Tiva board.



The first important thing for this lab is the GPIO configuration. When the processor has started executing, but before you can run application software on the processor, it must be initialized, including loading the appropriate software-configuration. The "Lesson 10: GPIO Ports and Configurations"describes the detailed steps that the software must take to initialize the GPIO Ports after reset.

Creating a New Project

Launch the Keil μVision5 IDE, create a New Project, add MyDefines.h to the Source Group, and and add the Common folder to the Include Paths option.



Write down the following configuration information into your lab report.



Lab Experiment

After the GPIO configuration, use the polling method to check the SW1 status, and then check SW2 status as shown on the following diagram.

flowchart1 s
Figure: Flowchart Diagram

  • For EK-TM4C123GXL Board:
    • Press SW1 (PF4) to turn on Red LED (PF1) for about 2 sec, then turn it off
    • Press SW2 (PF0) to turn on Green LED (PF3) for about 2 sec, then turn it off
  • For EK-TM4C1294XL Board:
    • Press SW1 (PJ0) to turn on LED1 (PN1) for about 2 sec, then turn it off
    • Press SW2 (PJ1) to turn on LED2 (PN0) for about 2 sec, then turn it off


Sample Firmware Code


Show your result to the instructor.



  1. When you hold down SW1 and SW2 simultaneously for a while (ex. more than 10 seconds), what happens on the LEDs? 


Using the following schematic diagram in Exercises. (For TM4C123G and TM4C1294 LaunchPad)

exercise 01

All LEDs must be turned off after reset (or power up),

Pin configurations:

DevicePort.Pin Signal TypePCTLDirection:Drive Mode