You are on page 1of 18

Texas Instruments MSP430 Launchpad

Development Tool

Copyright © 2012-2015 Page 1 of 18


Valparaiso University
1. Open the Launchpad development kit box.

2. Open the plastic bag that contains the Launchpad board.

3. Connect the Launchpad development board to the PC with the enclosed USB cable.

Copyright © 2012-2015 Page 2 of 18


Valparaiso University
4. The board is divided into two parts. The top third (the side with the USB connector) is
marked as EMULATION. This is the part of the board that talks to the PC and is
responsible for actually flashing your code onto the Texas Instruments MSP430
microcontroller. The power (PWR) LED should be on after you connect the board to the
PC. If not, ask your instructor for help.
The bottom two-thirds are for the microcontroller (resting in a socket), two push-buttons,
a couple LEDs, and holes for connecting your board to the rest of the world.

Copyright © 2012-2015 Page 3 of 18


Valparaiso University
5. Open the Code Composer Studio program. It can be found under the START menu.

Copyright © 2012-2015 Page 4 of 18


Valparaiso University
6. When opened, the Code Composer Studio program should look something like this:

7. Under File, select New, then select CCS Project.

Copyright © 2012-2015 Page 5 of 18


Valparaiso University
8. This will open the New CCS Project window. Enter a name for your project and make
sure the Use Default Location box is checked.
For the Variant, make sure you select the MSP30Gxxx Family, the select the
MSP430G2553 for the device.
Under Project templates and examples, select the Empty Project (with main.c).
Click Finish when you are ready.

Copyright © 2012-2015 Page 6 of 18


Valparaiso University
9. When the project wizard is done, the new project will be added to the Projects
Explorer window, and the main.c file should be opened.

10. The program we will be starting with is shown below.

#include <msp430g2553.h> // Register definitions

void main(void)
{
unsigned short int i;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P1DIR = P1DIR | 0x01; // P1.0 is an output

while(1)
{
P1OUT = P1OUT ^ 0x01; // Toggle P1.0

for(i=0 ; i<5000 ; i++);// Delay loop

}//end while(1)

}//end main()

Copyright © 2012-2015 Page 7 of 18


Valparaiso University
11. The #include statement has all of the statements that correlate the registers names
(such as P1DIR) with their addresses in RAM.

12. The first line in main disables the watchdog timer. The watchdog timer is used in many
applications (especially mission critical programs) to verify the microcontroller is
operating properly. For now, it simplifies our programs to disable the watchdog timer.

13. The following line configures the microcontroller to use pin P1.0 as a digital output.
Note, the MSP430 microcontroller has a reduced instruction set (it is a RISC
microcontroller). Therefore, it does not include operations that work on individual bits.
Therefore, all of our operations will be on bytes, not bits. The instruction

P1DIR = P1DIR | 0x01;

takes the logic OR of P1DIR with 0x01. The result is that the least significant bit (lsb)
of P1DIR will be HI.

Copyright © 2012-2015 Page 8 of 18


Valparaiso University
14. Inside the while(1) loop are two C statements. The first takes the bit-wise XOR (^)
of the contents of P1OUT and 0x01. Recall the XOR truth table:

P1OUT is being bit-wise XOR-ed with 0000 0001 binary. The 7 most significant bits
(msb) of P1OUT are being XOR-ed with 0. The output of any bit XOR-ed with 0 will
simply be the original bit:
P1OUT.7 ^ 0 = P1OUT.7
P1OUT.6 ^ 0 = P1OUT.6
P1OUT.5 ^ 0 = P1OUT.5
P1OUT.4 ^ 0 = P1OUT.4
P1OUT.3 ^ 0 = P1OUT.3
P1OUT.2 ^ 0 = P1OUT.2
P1OUT.1 ^ 0 = P1OUT.1

The least most significant bit of P1OUT (P1OUT.0) is XOR=ed with 1. From the
truth table, the result will be the complement of P1OUT.0.
P1OUT.0 ^ 1 = P1OUT.0

Therefore, the net effect of the instruction leaves the 7 msb of P1OUT unchanged, but
toggles the lsb, P1OUT.0.
P1OUT = P1OUT ^ 0x01;

Copyright © 2012-2015 Page 9 of 18


Valparaiso University
15. After this instruction, the program goes into a delay implemented by the for loop.
for(i=0 ; i<5000 ; i++);

16. Copy the code, and paste it into the main.c edit window.
If anything is misaligned, go ahead and straighten it out.

17. Click the Save icon near the top right corner of the screen.

Copyright © 2012-2015 Page 10 of 18


Valparaiso University
18. Click the Build Active Project icon near the top right corner of the screen.

19. The program will compile.

20. The results will be shown in the Console and Problems windows. If there are any
errors shown in the Problems window, you may have accidentally changed the code.
Go back and correct the errors. You can disregard any warnings at this time.

Copyright © 2012-2015 Page 11 of 18


Valparaiso University
21. We are now ready to load the program onto the microcontroller. Click the Debug
button.

22. The Debug interface looks like this:

Copyright © 2012-2015 Page 12 of 18


Valparaiso University
23. The Console window at the bottom of the screen shows that the program used 176 bytes
of program (flash) memory and 2 bytes of data (RAM) memory.

24. You can start the program by pressing the Resume button on the toolbar.

Copyright © 2012-2015 Page 13 of 18


Valparaiso University
25. Your red, P1.0 LED should now be blinking!

26. Click on the Terminate button to leave the debugger.

Copyright © 2012-2015 Page 14 of 18


Valparaiso University
27. This takes you back to the place where you can edit your code.

28. Modify the for loop to take four times as long:


for(i=0 ; i<20000 ; i++) // Delay loop (was 5,000)

29. Save your program and Build it. When it is done, go ahead and click Debug.

30. When you are in the Debugger, go ahead and Resume your program.

Copyright © 2012-2015 Page 15 of 18


Valparaiso University
31. Leave the Debugger and go back to the C/C++ Perspective screen one more time, and
let us modify your program again. First, change the number of iterations of the for loop.

for(i=0 ; i<40000 ; i++) // Delay loop (was 20,000)

32. Next, change the i variable's type to:

short int i;

33. Save and Build the modified program. Click the Debug button and Resume your
program again. Does the LED blinking slow down? Why or why not? What frequency
is the LED toggling at now?

Copyright © 2012-2015 Page 16 of 18


Valparaiso University
34. Quit the Debugger and modify your program as shown below:

#include <msp430g2553.h>

void main(void)
{
unsigned short int i;

WDTCTL = WDTPW + WDTHOLD;

P1DIR = P1DIR | 0x01;


P1REN = P1REN | 0x08;
P1OUT = P1OUT | 0x08;

while(1)
{
if (0x08 & P1IN)
{
P1OUT = P1OUT ^ 0x01;

for(i=0 ; i<5000 ; i++);


}

else
{
P1OUT = P1OUT ^ 0x01;

for(i=0 ; i<20000 ; i++);


}

35. Create a flow chart for the new program.

36. Save and Build your modified program. Click on the Debug button and Resume
your program. Demonstrate the program functionality matches your flow chart.

Copyright © 2012-2015 Page 17 of 18


Valparaiso University
All tutorials and software examples included herewith are intended solely for
educational purposes. The material is provided in an “as is” condition. Any
express or implied warranties, including, but not limited to the implied warranties
of merchantability and fitness for particular purposes are disclaimed.

The software examples are self-contained low-level programs that typically


demonstrate a single peripheral function or device feature in a highly concise
manner. Therefore, the code may rely on the device's power-on default register
values and settings such as the clock configuration and care must be taken when
combining code from several examples to avoid potential side effects.
Additionally, the tutorials and software examples should not be considered for use
in life support devices or systems or mission critical devices or systems.

In no event shall the owner or contributors to the tutorials and software be liable
for any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services; loss of
use, data, or profits; or business interruption) however caused and on any theory
of liability, whether in contract, strict liability, or tort (including negligence or
otherwise) arising in any way out of the use of this software, even if advised of
the possibility of such damage.

Copyright © 2012-2015 Page 18 of 18


Valparaiso University

You might also like