Msp430 Manual
Msp430 Manual
Learn how to blink the on-board Red LED on the MSP430 LaunchPad
Hardware setup
1. The MSP-EXP430G2 LaunchPad kit includes everything you need out of the box
2. To start programming, you'll first have to install CCS which contains the required drivers for
your new MSP-EXP430G2 LaunchPad kit
3. Plug your MSP-EXP430G2 LaunchPad into the PC with the included USB cable
4. If prompted, let Windows automatically install the software.
3. Once CCS is opened, we can create a new project by going to File > New > CCS Project
4. This will open up the "New CCS Project" Window. Within this window, we need to do 2
things. Name our project & choose our Device Variant. Let's name our project "Blink_LED"
We also need to choose the appropriate MSP430 device. For this tutorial, we will program
the MSP430G2553 device that comes pre-populated on the MSP430 LaunchPad. (Due to
the simplicity of this particular tutorial, any of the MSP430G2xx devices will work for this
example!) Then, click "Finish"
Writing code
Now, we have our blank canvas! We can finally start writing code!
1. #include <msp430g2553.h>
2.
3. unsigned int i = 0;
4.
5.
// Initialize variables. This will keep count of how many cycles
between LED toggles
6.
7.
8. void main(void)
9. {
10.
11.
12.
13.
14.
// This line of code turns off the watchdog timer, which can reset the
device after a certain period of time.
15.
// P1DIR is a register that configures the direction (DIR) of a port
pin as an output or an input.
16.
17.
P1DIR |= 0x01;
18.
19.
20.
// To set a specific pin as output or input, we write a '1' or '0' on
the appropriate bit of the register.
21.
22.
23.
// P1DIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PIN1><PIN0>
24.
25.
26.
// Since we want to blink the on-board red LED, we want to set the
direction of Port 1, Pin 0 (P1.0) as an output
27.
28.
// We do that by writing a 1 on the PIN0 bit of the P1DIR register
29.
// P1DIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PIN1><PIN0>
30.
// P1DIR = 0000 0001
31.
// P1DIR = 0x01
<-- this is the hexadecimal conversion of 0000
0001
32.
33.
34.
35.
for (;;)
36.
37.
// This empty for-loop will cause the lines of code within to loop
infinitely
38.
39.
{
40.
41.
42.
43.
P1OUT ^= 0x01;
44.
45.
// Toggle P1.0 using exclusive-OR operation (^=)
46.
47.
// P1OUT is another register which holds the status of the LED.
48.
// '1' specifies that it's ON or HIGH, while '0' specifies that it's
OFF or LOW
49.
// Since our LED is tied to P1.0, we will toggle the 0 bit of the
P1OUT register
50.
51.
for(i=0; i< 20000; i++);
52.
53.
// Delay between LED toggles. This for-loop will run until the
condition is met.
54.
//In this case, it will loop until the variable i increments to 20000.
55.
}
56.
}
1. Now that we have written our code, we can download it to our MSP430 LaunchPad that is
plugged into the USB port! We can do this by clicking the debug button
2. Clicking the Debug button will take us to the CCS Debug View. Here, we can press the Run
button to start running the code we just wrote.