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
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 or .
- 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 EK-TM4C123GXL LaunchPad comes with an RGB LED and two user buttons. Table 1 shows how these features are connected to the pins on the microcontroller.
Table 1: User Switches and RGB LED Signals
|GPIO Pin||Pin Function||User Device|
|PF1||GPIO||RGB LED (Red)|
|PF2||GPIO||RGB LED (Blue)|
|PF3||GPIO||RGB LED (Green)|
In your code, you need to configure GPIO Port F pin 0 and pin 4 as inputs; Port F pin 1, pin 2 and pin 3 as outputs.
Note: The SW1 and SW2 are directly connected with GND. Therefore, these pins are as negative logic input, you have to enable the internal resistor for these pins.
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.
After the GPIO configuration, use the polling method to check the SW1 status, and then check SW2 status as shown on the following 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.
- 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)
All LEDs must be turned off after reset (or power up),