EasyManuals Logo

Texas Instruments MSP430 Student Guide

Texas Instruments MSP430
398 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #82 background imageLoading...
Page #82 background image
Lab 2 – CCSv5 Projects
2 - 44 MSP430 Workshop - Programming C with CCS
2. Let’s quickly examine the code that was in the template.
This code simply blinks the LED connected to Port1, Pin0 (often shortened to P1.0).
#include <msp430.h>
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to out-put direction
for(;;) {
volatile unsigned int i; // volatile to prevent op-timization
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
i = 10000; // SW Delay
do i--;
while(i != 0);
}
Other than standard C code which creates an endless loop that repeats every 10,000 counts,
there are three MSP430-specific lines of code.
As we saw earlier, the Watchdog Timer needs to be halted.
The I/O pin (P1.0) needs to be configured as an output. This is done by writing a “1” to bit
0 of the Port1 direction register (P1DIR).
Finally, each time thru the for loop, the code toggles the value of the P1.0 pin.
(In this case, it appears the author didn’t really care if his LED started in the on or off
position; just that it changed each time thru the loop.)
Hint: As we mentioned earlier, we will provide more details about the MSP430 GPIO
features, registers, and programming in the next chapter.
Build, Load, Run
3. Build the code. Start the debugger. Load the code.
If you don’t remember how to use the easy button (or the long method), please refer back to
lab_02a_ccs.
4. Let’s start by just running the code.
Click the Run button on the toolbar (or press F8)
You should see the LED toggling on/off.
5. Halt the debugger … don’t terminate!

Table of Contents

Other manuals for Texas Instruments MSP430

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments MSP430 and is the answer not in the manual?

Texas Instruments MSP430 Specifications

General IconGeneral
BrandTexas Instruments
ModelMSP430
CategoryMicrocontrollers
LanguageEnglish

Related product manuals