Lab 2 - Embedded Programming and Interfacing Review Preparation
Lab 2 - Embedded Programming and Interfacing Review Preparation
Preparation
Import “EGEE-406 Template” into CCS and rename it Lab 2
Watch the related video(s) here
Purpose
The purpose of this lab is to learn simple programming structures in C. You will also learn
how to estimate how long it takes to run the software and use this estimation to create a time
delay function. You will learn how to use the clock profiling feature in CCS to estimate the time
delay. Programming skills you will review include interfacing, toggling, if-then, functions, and
looping.
System Requirements
The EDUBase board has 4 input switches (a.k.a., pushbuttons) and 4 output LEDs (see Figure
1). For this lab, we will use the LSB (rightmost) switch and LED. The switches on the EDUBase
board are positive logic which means the PD0 signal will be 0 (low, 0V) if the switch is not
pressed, and the PD0 signal will be 1 (high, 3.3V) if the switch is pressed. The red LEDs are also
positive logic which means if the software outputs a 1 to PB0 (high, 3.3V) the LED will turn ON,
and if the software outputs a 0 to PB0 (low, 0V) the red LED will be OFF. In this lab, you will first
debug on the real board using the switch and LED on the EDUBase board. Normally, we would
“debounce” the switches, but we are not going to worry about that for this lab. The overall
functionality of this system is described in the following rules:
1. Make PB0 an output and make PD0 an input
2. The system starts with the LED ON (make PB0 =1)
3. Delay for about 100 ms (using a loop(s)). Keep in mind the clock is 80MHz.
4. If the switch is pressed (PD0 = 1), then toggle the LED once, else turn the LED ON
5. Repeat steps 3 and 4 over and over
Figure 1: EDUBase board (black board) with TI Tiva LaunchPad (red board). LEDs and PBs (blue box).
1/3
On the TM4C123 the default clock is 80 MHz. Later we will use the clock system. For now,
however, we will run at 80 MHz. To estimate the delay, you will need to use the clock-profiling
feature of CCS to estimate the clock cycles, and then hand calculate the elapsed time (see the
“Profiling the Clock” slides in Lecture 3).
Procedure
The basic approach to this lab will be to develop and debug your system using a positive
switch (PD0) and a positive logic LED (PB0) on the EDUBase and TM4C123 boards.
a) Design a function that delays about 100 ms. First, draw a flowchart for the delay function,
and then write the pseudo code. To implement a delay, you could set a variable to a large
number, and then count it down to zero. With a clock of 80 MHz, there are 8,000,000 clock
cycles in 100 ms. You need to know how long it takes to execute the loop once, then
determine the number of times you need to execute the loop to create the approximate 100
ms delay.
b) Write a main program that implements the I/O system. The pseudo code and flowchart are
shown in Figure 2, illustrating the basic steps for the system.
main Initialize ports
Set PB0, so the LED is ON
loop Delay about 100 ms
Read the switch and test if the switch is pressed
If PD0=1 (the switch is pressed), toggle PB0 (i.e., flip from 0 to 1, or vice versa)
If PD0=0 (the switch is not pressed), set PB0, so the LED is ON
Go to loop
2/3
c) Use the clock profiling feature in CCS (see Lecture 3) to measure the delay function.
d) Load your software onto the board and test it. If the PD0 switch is not pressed, then the red
LED is on. If the PD0 switch is pressed, then the red LED toggles causing it to blink.
Demonstration
You will show the instructor your program operation on the real board. Be prepared to
explain how the delay function works. How would it be different if the delay were 1 ms instead
of 100 ms? The instructor will pick an instruction from your code and ask you which addressing
mode it uses. Execute the program step-by-step and run to cursor.
Lab Report
The lab report is how I will grade you on your labs. Usually, the report is due 2 to 3 days
following the completion of the lab (see Canvas for due dates). However, due to unforeseen
circumstances, due dates may change. I will try my best to keep everyone informed of any
changes. With this said, it is your responsibility to turn the report in during the scheduled due
date. There is a 10% penalty for late reports. Your report must be in MS Word Doc format.
Submitting the report in another format will result in a 10% penalty. Your lab report must
include the cover sheet from the lab report template available on Canvas. Not including the
cover sheet will result in a 10% penalty. The template contains instructions for the report and
the rubric used for grading the labs. Please, read it thoroughly. Don’t forget to include pertinent
information such as code, flowcharts, waveform output, etc. in your report. Please, no
“spaghetti” code, keep your code clean and use comments. Remember, your code will affect
your lab grade. If I can’t understand it, then I will assume it’s incorrect.
3/3