Tiva Lab 02: Using GPIO to Control LED

Objective

  • 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 KitEK TM4C123GXL s or EK-TM4C1294XL LaunchPad KitTM4C1294XL 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.

 

Procedure

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 and create a New Project.

Configurations

Write down the following configuration information into your lab report.

 

Sample Firmware Code

 

GPIO Ports and Pins Configuration and Main Code

The Sample Firmware code and steps are shown in "Lesson 10: GPIO Ports and Configurations". Copy and paste the Sample Firmware code into your project, then modify the code to configure the GPIO Ports and pins based on the above configuration table.

After port configuration, using the polling to check the SW1 status, and then check SW2 status as shown on the following diagram.

Lab Experiment

Implement the following flowchart:

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

 

Questions

  1. When you press and hold the SW1 and SW2 simultaneously for a while, what happen on the LEDs?
  2. Modify the code to implement the following function. Post your code and flowchart diagram on the report.
    • If just SW1 is pressed, turn on Red LED (or LED1) for about 2 second then turn it off
    • If just SW2 is pressed, turn on Green LED (or LED2) for about 2 second then turn it off
    • If both SW1 and SW2 are pressed at same time, turn on both LEDs for about 2 second and then turn it off

Exercises