University of California, Davis
Department of Electrical and Computer Engineering
EEC 7, Fall 2025
Lab 1: General Purpose Output
Overview:
In this first lab, we will walk through the basics of writing to digital output pins on the
MSP432P4111. While we will provide you with the information you will need to know for this
lab, further documentation for the MSP432P4111 board is available on the course Canvas page.
The following resources may be useful and are listed for your reference. They will be referenced
at appropriate points throughout this lab.
•
MSP432P4111 pinout diagram: MSP432P4111 SimpleLink™ Microcontroller LaunchPad™
Development Kit User's Guide (mouser.com)
Note, for this and all other labs, the launchpad’s watchdog timer must be disabled. The watchdog
timer is used to reset the microcontroller after a set time interval, but we will be disabling it for
class purposes. Be sure to always include the snippet of code in Example 1 within your main
function to disable this timer.
1 // Stop watchdog timer
2 WDT_A_hold(WDT_A_BASE);
Example 1: Stopping the Watchdog Timer
Due Date:
All labs will have a due date a week after the lab is introduced. This means that the lab will
require a check-off by the end of your next lab session, and a report will be due by 11:59 on the
day the check-off is due.
•
Lab 1 is due at the end of your lab section during the week of 10/27.
1
•
Lab 1 Report is due by 11:59 pm on the day Lab 1 checkoff is due. You will submit your
Lab Report on Canvas.
Important Practical Notes:
1.
Do NOT use Copy-and-Paste from a pdf into Code Composer Studio! This can
insert hidden control characters into your code which will cause your compilation to
fail for no apparent reason. This can be very difficult to debug because the control
characters are invisible. You should just type in the code by hand. You can use Copyand-Paste from another CCS file, if desired, but not from a pdf!
2.
If you make a copy of a CCS Project and rename it, do NOT use the previous
Launch / Debug Configuration when you launch the Debugger!! Using a previous
Launch Configuration will fail and can be difficult to fix. Make sure to answer ‘No’
to the question or ‘Cancel’ if you are given multiple choices of previous Launch
Configurations. This will allow CCS to create a new Launch Configuration for your
new project.
Coding with the MSP432P4111:
The MSP432P4111 launchpad has lots of pins available for general purpose input and output
(GPIO) functions. Every physical pin on the board is identified by two numbers: port number
and pin number. The common format to represent these port and pin number pairs that you will
find in Texas Instrument’s documentation is PX.Y or PX_Y for the output identified by port X
and pin Y. We will also adopt this notation for this and future labs. Pins will also be identified by
the same port/pin number pair in the code we will write. Figure 1, shown below, identifies the
pins’ names and locations available on the MSP432P4111. Many of the pins’ names are also
printed on the launchpad itself.
For example, the my_blinkled demo program seen in the previous tutorials toggles LED1 on and
off periodically. From the schematic in Figure 2, we find that LED1 corresponds to P1.0 (aka
port 1, pin 0) as seen on the left of the figure.
2
Fig. 1: MSP432P4111 Launchpad Pinout Diagram [Original Source]
3
Fig. 2: MSP432P4111 User LEDs (LED1 and LED2)
To use a pin for digital output, two things need to be done. First, we need to include the correct
libraries. Secondly, we must set the pin as an output. Once the setup steps are complete, we can
write to the digital output pins. There are three functions available to write digital outputs to
pins:
1.
GPIO_setOutputHighOnPin() : This function sets the output of the given port and
pins to a logical one, or high voltage. Multiple pins can be set at the same time if they
belong to the same port. This is accomplished by performing a bitwise OR on the pin
numbers.
2.
GPIO_setOutputLowOnPin() : This function is identical to the previous one except
that it sets the output to a logical zero, or low voltage. Again, multiple pins belonging
to the same port can also be specified by performing a bitwise OR on the pin
numbers.
3.
GPIO_toggleOutputOnPin() : This function will flip the specified pin(s) output
from a logical zero to a logical one or vice versa. Multiple pins belonging to the same
port can also be specified by performing a bitwise OR on the pin numbers.
The my_blinkled demo program is a good example of using a digital output pin. A simplified
example of typical usage is provided below in Example 2.
4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Driverlib include must be specified at the top of the file.
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
// Configure the pin as an output
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
// Set the output to LOW on P1.0
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
// Set the output to HIGH on P1.0
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
// Flip output on P1.0
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
Example 2: Configuration options for using an output pin.
Other ports and pins can be specified using similar constants to the ones seen in Example 2 on
lines 5, 8, and 11 by replacing the numbers with the correct port and pin numbers. For example,
if you wanted to instead use P2.6 for output instead of P1.0 in the previous example you would
use the constants “GPIO_PORT_P2” and “GPIO_PIN6” instead.
Part 1: Building and Running an Example Program
For this lab, we will use either the my_blinkled or the EEC7_Lab1 demo program as a starting
point. These projects are nearly identical and can be found on the course Canvas page. Your first
task is to run one of these programs to receive credit for setting up CCS and flashing the
microcontroller. We also ask that you adjust the timing of the LED blinking to allow the LED to
remain on or off for approximately 1 second.
The only difference between my_blinkled and EEC7_Lab1 is that EEC7_Lab1 uses printf() to
display “Hello, world!” at the start of the program. In Part 2, you will be using printf() and
scanf() so you will need to include the header file <stdio.h>.
5
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
int main(void)
{
volatile uint32_t i;
// Stop watch dog timer
WDT_A_hold(WDT_A_BASE);
// Set P1.0 to output direction
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
while(1)
{
// Toggle P1.0 output
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
}
// Delay
for(i=100000; i>0; i--) {;}
}
Example 3. main.c in my_blinkled project
In Part 1, you will run the demo program with the adjusted timing. Then in Part 2, you will
change to the project to take user input. You should be familiar with taking user input from a
console via scanf() and printing the output with printf(). Your program will allow the user to
select which color to blink on the LaunchPad’s RGB LED.
Follow the instructions below to complete Part 1. This lab assumes that Code Composer Studio
(CCS) and the MSP432 SDK have already been installed, such as on the lab PCs in 2110. To
install CCS on your personal machine, please follow the tutorial provided on Canvas.
1.
Launch the CCS application and open your workspace.
a.
Select a workspace in your user space, such as
C:\Users\<User Name>\Documents\EEC7_workspace
i. Make sure to specify a directory where you have write access. When
completed select “Launch.”
b.
Do not select the “Use this workspace as the default option and do not ask
again” checkbox. This will cause other users problems on the shared lab
6
machines and may make things more difficult for you on a personal computer
if you need to use a different folder for other labs in the future.
2.
Download the my_blinkled demo project into your workspace from Canvas.
a.
From the File tab, select “Import Project(s)” or “Open Projects from File
System” to establish the my_blinked folder as a project.
3.
Plug your microcontroller into your computer’s USB port now. Windows should take
a minute to automatically install the device drivers if it is your first time plugging in
your device. Once plugged in, click the hammer Build Button
which is located
in the toolbar at the top of the screen, to compile the program.
a.
A console pane should pop up at the bottom of the screen to show the
compilation results. If all went well, there should be no red errors and the
console should read “ **** Build Finished **** ”
4.
Now that the code has been compiled successfully, we need to test it on the device.
Click the green bug (indicates debugging) button located in the toolbar to the left of
the build button.
a.
If it is your first time running a program with CCS, you may get a warning
indicating that a firmware update is required. If so, click “Update.”
Fig. 3: Firmware update warning.
b.
After a couple of minutes, the debug pane in the top left of the screen should
populate with the main() function highlighted. The program is now loaded
onto the microcontroller and is paused waiting for our command to start. If
any lights were blinking on the board before, they should be stopped now.
5.
Click the green play button, located in the toolbar, to run the program. If all goes
well, the red LED at the bottom of the board should now be blinking.
7
Congratulations! You’ve successfully compiled and run your first application on the
MSP432P4 microcontroller.
6.
Click the red stop button, located in the toolbar at the top of the screen, to stop the
debugging phase. This won’t necessarily stop the board from running the code but
will stop CCS from tracking the board and return to the CCS editor perspective.
7.
On line 76 of main.c, change the initial value of the variable “i” from 100,000 to
300,000 to allow more time between the blinks (approximately one second). It should
look like Example 3 given that “i” is already declared.
1 // Delay statement, approximately one second.
2 for(i = 300000; i > 0; i--);
Example 4: Delay statement to pause execution for approximately one second.
8.
Run the demo program again with the one second delay loop and get a checkoff from
your TA.
Part 2: Controlling the RGB LED
1.
Set up a new project for your Lab 1 program. Feel free to either continue working
from my_blinkled project or import the template project named EEC7_Lab1 in
Canvas.
2.
In this program, you will configure the RGB LED pins as outputs rather than just the
Red LED that was used in my_blinkled. You should initialize all of the LEDs to off
by setting the associated output pin to logic low.
3.
Your program should use printf() and scanf() to ask the user to input the color of the
LED to blink and read the user’s response. The user can enter a character to indicate
the color to blink, such as ‘r’ to blink the Red LED (P2.0), ‘g’ to blink the Green LED
(P2.1), ‘b’ to blink the Blue LED (P2.2), or ‘w’ to blink all three colors at once, which
corresponds to White.
4.
Based on the user input, you should blink the appropriate color LEDs in an infinite
loop using an approximately one-second delay loop. To decide which output pins to
toggle, your program can use a switch-case or an if–else if construct.
8
5.
You are only required to be able to blink the LED Red, Green, Blue, or White, where
the LED should toggle between the desired color and Black (i.e. all LEDs off). Seven
possible colors, not counting Black, can be output on the RGB LED as shown in
Table 1. If desired, you can extend your program to blink other colors from the table.
One option is to use the first letter of each color (‘r’, ‘g’, ‘y’, ‘b’, ‘m’, ‘c’, ‘w’) to
blink the corresponding color. However, you are only required to implement Red,
Green, Blue, and White.
6.
Once your program works, have your TA sign and date your verification sheet.
LED B (P2.2)
0
0
0
0
1
1
1
1
LED G (P2.1)
LED R (P2.0)
Output Color
0
0
Black
0
1
Red
1
0
Green
1
1
Yellow
0
0
Blue
0
1
Magenta
1
0
Cyan
1
1
White
Table 1. RGB LED Output Colors
Grading Rubric (50 points):
•
80% Lab Checkoff
•
20% Lab Report
Checkoff Points:
Task
Points
Build and Run Example Project
5
Change Delay Timing
5
Blinking RGB LED
5
Input Character Handling
10
Color Selection (Red, Green, Blue, White)
15
9
Example
Lab Report:
Submit your code (main.c only) with a typed one-page lab report (pdf file) to Canvas. The lab
report should give a brief description (~1-2 paragraphs for each part) describing how the
program worked and what difficulties you encountered. It’s ok to submit pieces of your code for
explanation, but please do not submit your entire source code (this is why the main.c file is
included in the submission). Consider your grammar, spelling, and report format before
submission.
10
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )