Tiva Lab 02: Using GPIO to Control LED
- Understand I/O operation in Tiva TM4C LaunchPads
- Learn the steps of GPIO configuration on Tiva TM4C LaunchPads
- Learn how to read data from the input pin, and write a data to output pin
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 to the 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 switches 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 add the Common folder to the Include Paths option.
Write down the following configuration information in your lab report.
Sample Firmware Code
Now, a customer asks you to remodel his house. He wants to use a microcontroller to control all lighting systems and the doorbell for his house. There are three types of control systems could be used in the house:
- Uses a button to control the doorbell: when the user presses the doorbell button, the doorbell will be triggered. Unless the user releasee the button.
- Uses a switch to control light: when the user presses the switch, the light is on. Press again to turn off the light.
- Uses two switches to control the stair light: two switches are installed on the first and second floors near the stairs. When the user presses any switch, the light is on, pressing any switch again to turn off the light.
Then, you will make a prototype system to simulate all types of control systems. The prototype circuit is shown below:
- The SW1 is used to control the buzzer (doorbell).
- The SW2 is used to control LED1
- The SW3 and SW4 are used to control LED2, which is installed on the stair.
You need to create three functions for each control system.
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
Show your results 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),