CECS 346 Lab 2 Switch and LED Interface solution


Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment


4.7/5 - (6 votes)


You will need a LaunchPad, two push buttons, two 10Kё resistors, three color LEDs: red, yellow,
and green, and three resistors for the LEDs.

Book Reading: Textbook Sections 2.7, 4.2
Starter project: Lab1, use Lab2starter.c as your starter C code, rename it to CECS346Lab2.c. You
cannot change the existing code in Lab2starter.c, but you can add missing code to this file. You
cannot add more header files, such as: #include “tm4c123gh6pm.h”. You are required to define
all the registers used in this lab and to follow the coding format provided for file header


Lab 2 is our first lab requiring you to build circuits on the breadboard and connect them to the
LaunchPad. The purpose of this lab is to learn how to interface a switch and an LED. You will
perform explicit measurements on the circuits to verify they are operational and to improve
your understanding of how they work.

System Requirements:

In this lab, you will build two switch interface that implement positive logic, and you will build
three LED interface that implement positive logic. You will attach this switch and LED to your
breadboard, and interface them to your TM4C123. Overall functionality is given below:

1) Port B will be used to control 3 LEDs: green(PB0), yellow(PB1), red(PB2)
2) Port E: PE0(sw1) and PE1(sw2) will be used for the two switches
3) The system starts with the green LED on, the other two LEDs off. The three LEDs aligned in
the following order green(PB0), yellow(PB1), red(PB2).

4) Wait about 1 second
5) If the sw1 is pressed, the currently on LED will be turned off, the next LED will be turned on.
6) If sw2 is pressed, currently on LED will flash at a speed of 1s: for one flash: 0.5 second off,
then 0.5 second on.
7) If both sw1 and sw2 are pressed, we should observe current led flash and then move to the
next one.
8) Repeat steps 4 to 6.

Use edXLab10.dll for simulation parameter. see Figure 1 below. It will provide a traffic light
controller simulation interface shown in Figure 2. We only need one set of color LEDs
connected to port B and two switches connected to port E.

Figure1. Simulation setting for Lab 2. Figure 2. Traffic Light simulation interface.
x Note: when Debug your program, you may get the following error messages. You can
ignore these messages. They won’t affect your simulation and running code on your

Error: attempt to change CR while locked. You should unlock first
Error: attempt to change CR while locked. You should unlock first

Procedure :

1. Design your hardware system and draw a circuit diagram. Please see an example below. You
can use “Eagle Cad” from Autodesk or schemit (an online tool to draw schematic:
https://www.digikey.com/schemeit/project/) from digikey. If you use schemit:
you can find launchpad symbol by typing TM4C123 on search parts, then click

2. Design and implement your software, simulate it with keil uVision.
3. Download your program to Launchpad and test it on board.
Figure 2. Hardware connection example.


1) Demonstrate your lab on board through Zoom and video record your demonstration.
2) Submit a lab report. Your lab report format is attaching the following items to the end of
this lab description: schematic(circuit diagram, hand-drawn schematic is NOT acceptable), a
picture of your hardware system and a link to your demonstration video.
3) Software source code: CECS346Lab2.c.
Video Link: https://youtu.be/lU0aPtGMOx4