Overview
The purpose of the assignment is to develop a basic understanding and skills programming of input/output ports and device polling.
The assignment examines hardware polled input from a push button.
Assignment 1
The assignment is based on the flashing LED of the MSP430 Getting Started notes.
Alternate flashing of the red and green LEDs at intervals of approximately one second.
When red is ON the green is OFF and vice-versa.
Increasing the for-loop limit will increase the delay between LED toggling.
Keep in mind that:
char : signed 8-bit integer
unsigned char : unsigned 8-bit integer
int : signed 16-bit integer
unsigned int : unsigned 16-bit integer
long : signed 32-bit integer
unsigned long : unsigned 32-bit integer
Assignment 2
The assignment is based on the polled push button of the MSP430 Polling notes.
Turn On the red LED when the push button is pressed down, Off when up.
Assignment 3
The assignment is based on Assignment 1 and 2.
Alternate flashing of the red and green LEDs.
When push button is down, red is flashing; when up, the green is flashing.
Assignment 4
The assignment uses the Temperature program discussed in class.
1. Download and extract example project: Temperature.zip
2. In CCS:
File | Import | Existing CCS Projects
Select the Temperature directory.
Click through to complete.
3. Debug the program.
View | Expressions | Add New Expression | DegreeF
Set a breakpoint at: __no_operation();
Execute to the breakpoint a few times, noticing DegreeF
Place your finger on the MSP430 chip.
Execute to the breakpoint a few times, noticing DegreeF
4. Record the lowest and highest temperature measured by placing you finger on top of the MPU. The thermistor is encased in plastic and heated by the chip so is not very accurate.
Assignment 5 (Bonus)
The assignment uses the Temperature program from Assignment 4.
Modify the program to:
1. Compare the current temperature reading with the previous,
2. Turn on the green LED if cooler,
3. Turn on the red LED if warmer,
4. Turn off the red and green LEDs if no change,
5. Delay approximately one second between temperature readings.
The LEDs will likely alternate due to thermal noise. Placing an object warmer or cooler than the ambient temperature should result in a temporary predominance of red or green.
Turn in
1. Cover page - Your name, date, and Homework 8. Staple all papers together.
2. Listing of Homework 8 Assignment 1, 2, 3 (and 5 for bonus points) programs and Assignment 4 results.
3. In Assignment 3, set a breakpoint to display registers Port_1_2 similar to at right when the push button is down. Capture and print the registers display.
4. Demonstration - Post a video demonstration of Assignment 3 program execution to OnCourse as HW8.
1. Start | All Programs | Texas Instruments | Code Composer Studio | Code Composer Studio
2. License Setup Wizard (appears on first use)
Select: CODE SIZE LIMITED (MSP430)
3. Plug in the LaunchPad.
4. Download and extract example project: Blink_LED.zip
5. In CCS need to set the workspace to your username and import the Blink_LED project:
File | Switch Workspace | Other
Workspace: C:\Users\username
File | Import | Code Composer Studio | Existing CCS Projects
Browse to Blink_LED
6. View | Project Explorer | Select Blink_LED
7. Click the to build and start debugging.
If the following appears, click Ignore. Newer versions of LaunchPads are compatible but cause this complaint.
If the following appears, plug in the LaunchPad in again and Retry.
8. Press F5 keys to execute one statement at a time.
9. Continue executing to verify the LaunchPad LED turns On and Off.
Getting Started at Home
Download and install Code Composer Studio:
There should be a desktop icon to start Code Composer Studio:
Follow above instructions starting at 2.
Debugger
Debugging video
When starting a debugging session, you may need to View | Debugger to see the debug panels as below.
To view Input/Output pins:
1. Click the Registers tab.
2. Select Port_1_2 (connected to the LED's and push buttons) to expand the view.
To set a breakpoint:
1. Stop the program by clicking the red square.
2. Right-click the highlighted line below.
3. Select Breakpoint.
4. Click Debug.
F8 to run to the breakpoint. Repeat several times.
1. Notice the change of P1OUT as the LED turns ON and OFF.
Creating a new Code Composer Studio Project
1. File | New | CCS Project
2. Use the settings below.
Device Variant MSP430G2231
Empty Project (with main.c)
Writing Code
Copy and paste the example program over the generated main.c program.
Toggle green LED On and Off
#include <msp430g2231.h>
unsigned int i = 0;
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer.
P1DIR |= 0x40; // P1DIR configures direction port pin (DIR) output or input.
// 1 is output, 0 is input.
while(1) {
P1OUT ^= 0x40; // Toggle P1.6 using exclusive-OR operation (^=)
// P1OUT is another register which holds the status of the LED.
// 1 is ON, 0 is OFF
for(i=0; i < 20000; i++); // Delay between green LED toggles.
}
}