Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.

MSP430 LaunchPad Drive LED

From Texas Instruments Wiki
Jump to: navigation, search

by Aldo Briano

The blinking led is the “hello world” for microcontrollers. A little twist is given to this traditional program. The push button will be used to start and stop the two blinking LEDs. Also, an external LED will be interfaced to the MSP430.


Related Projects

Quick Start

  • Get LED
  • 100 Ohm Resistance
  • 2.15k Ohm Resistance
  • BJT NPN switching transistor
  • Download Code / Make Circuit
  • Enjoy!


If an external LED is going to be used, Jumper J3 must be open (removed). This will disable the onboard LED in the LaunchPad.
Parts used:


                 Launchpad images LED driving.png                                                         Launchpad images LEDBreadboard small.png

                         Fig. 1:  Schematic for Driving the LED                                                                     Fig. 2:  Circuit built using a Breadboard and a external LED


// MSP430 Blink LED / Start Stop Blinking with Button Demo - Software Toggle P1.0 & P1.6
// Description; Toggle P1.0 and P1.6 by xor'ing them inside of a software loop. To
// start/stop blink, an interrupt in Port 1 will toggle the condition statement. 
// ACLK = n/a, MCLK = SMCLK = default DCO
// MSP430x2xx
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | P1.6|-->LED
// Button -->|P1.3 P1.0|-->LED
// Aldo Briano
// Texas Instruments, Inc
// June 2010
// Built with Code Composer Studio v4
#include <msp430g2231.h>

#define LED_0 BIT0 
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
#define BUTTON BIT3

unsigned int blink = 0;

void main(void)
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
LED_DIR |= (LED_0 + LED_1); // Set P1.0 and P1.6 to output direction
LED_OUT &= ~(LED_0 + LED_1); // Set the LEDs off
P1REN |= BUTTON; //Enables a puller-Resistor on the button-pin
P1OUT |= BUTTON; //Writes a "1" to the portpin, tellling the resistor to pullup
P1IES |= BUTTON; //Triggers when you PRESS the button :: Pick one...
//P1IES &= ~BUTTON; // Triggers when you RELEASE the button :: ...or pick the other
P1IE |= BUTTON; //Enables the selector-mask for generating interrupts on the relevant pin

__enable_interrupt(); // Interrupts get enabled *here* - they were disabled thus far..

for (;;)

if(blink > 0)
P1OUT ^= (LED_0 + LED_1); // Toggle P1.0 and P1.6 using exclusive-OR

__delay_cycles(100000); // SW Delay of 10000 cycles at 1Mhz



// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
blink ^= 0x01;
P1IFG &= ~BUTTON; // P1.3 IFG cleared
LED_OUT &= ~(LED_0 + LED_1); // Clear the LEDs so they start in OFF state


Theoretical Background

It is essential to understand the electrical characteristics of your microcontroller. These are used to understand the compatibility with other components and the correct way to interface them. In our case, the MSP430 characteristics can be found in the datasheet from page 17 on. I am going to focus on Port inputs and output on page 21.

                                                                 Launchpad datasheets OutputPortsElectrical.png

As depicted the high-level output voltage is not Vcc as many could assume. There is a minor difference of typically 0.3 V. There is also an important fact mentioned in Note 1. “ The maximum total current, IOHmax and IOLmax, for all outputs combined, should not exceed +- 12 mA to hold the maximum drop specified.” This means for each pin we have a maximum output current of 1.5 mA. Also mentioned, that the maximum current for the port is 48 mA.

What does this information mean?

Let’s take our LED for an example. The typical LED you find/buy in electronics store have a If = 10mA and a Vf = 2V (ex. SLR-332VC3F). You cannot connect the LED directly to the MSP430 pin. In theory, you could, yet you would be exceeding the maximum current per pin, which is not recommendable. The way to interface this LED is to drive it using a transistor. The BJT transistor will be operated as a switch in its saturation and cutoff regions.  

                         Launchpad equation rb.PNG                              Launchpad images LED npn voltages.png                         Launchpad equations ic.PNG                        Launchpad equation ra.PNG

WARNING: Beta = Ic / Ib.  This mean the Ib = formula above is wrong:  It should read : Ib = Ic / Beta

                                                                                                           Sample LED interface circuit with equations.

  The calculations can be derived from the basic circuit equations of the diagram.  When picking a transistor, its datasheet must be analyzed for its characteristic values. To drive using a PNP transistor, the circuit is mirrored and the LED is connected to ground. With the current configuration, an output high voltage will turn on the LED, off otherwise.



Contrary to the LaunchPad PushButton example, LEDs use Digital Outs.  To select this functionality, PxDIR must be set to 1 (means output).  Afterwards, the output port can be written as any other register, simply using PxOUT = 0x01.  In page 8-3, the MSP430x2xx Familiy Guide explains this a little further:

  Launchpad datasheets Pxdir.pngLaunchpad datasheets Pxout.png

                                                                             Excerpts from the Digital I/O section in the MSP430x2xx Familiy Guide

In this example, conditional statements are used as a way to decide whether or not to blink. A variable is declared to store the blinking status. The push button will toggle this status to enable and disable blinking. Additionally, to achieve visible blinking, a software delay is used. Remember that the LaunchPad runs at a default of 1Mhz and the human eye cannot process that fast rate (without the delay, the LED appears that it is always on).

Future Ideas

  • Change the interrupt edge so that the LEDs blink only when the button is pressed
  • Use another push button and blink each LED with different buttons


  1. MSP430x2xx Family User Guide
  2. MSP430G2x31 Datasheet