Tag: MSP430 LaunchPad (MSP-EXP430G2)

MSP430 Launchpad: Using Buttons

Posted by on December 21, 2010


Sooner or later you’ll want a user interface, whether you’re working on a game or just trying to figure things out one of the simplest methods for human interaction would be a button. We’ll discuss how to setup and read input bits in the following paragraphs.

The code:

// MSP430 Launchpad - Blink onboard LED using onboard Switch (SW1).
//	GuShH - info@gushh.net

#include  "msp430x20x2.h" // Include the necessary header for our target MCU

void delay_ms(unsigned int ms ){ 		// Not really a milliseconds delay!
      unsigned int i;
      for (i = 0; i < = ms; i++){ 		// The operator is <=, I've yet to fix this site bug.

void do_led( int led, int delay ) {
	P1OUT = led;
	delay_ms( delay );

void main(void) {

	WDTCTL = WDTPW + WDTHOLD;		// Hold the WDT (WatchDog Timer)
	P1DIR |= BIT0|BIT6;       		// Setup the appropriate output bits	

	while(1) {

		if ( !(P1IN & BIT3) ){		// If not (port one input AND bit3 (sw1))
			do_led( BIT6, 2000 );	// Turn on LED 2
		}else{				// Otherwise...
			do_led( BIT0, 100 );	// Turn on LED 1



The quick explanation:

We'll deal with inputs very much the same way we would with an output, except we're reading instead of writing. Notice how we define the bits we want as "high" on P1OUT to light up our LEDs, provided the bits are set on P1DIR to "high" then those bits will act as outputs and every time P1OUT has one of these bits "high", your outputs will also go "high".

Likewise with our inputs, if P1DIR is set "low" on our target bit then all we have to do is read P1IN to know whether a button is being held down or not. Simple eh?

To recap: On port direction bits low = Inputs, bits high = Outputs

A word on de-bouncing:

For those of you unaware of switch bounce, I would like to give you a simple explanation of what it is: whenever you actuate a switch it's contacts bounce back and forth very rapidly as the metal vibrates after it's been bent and pushed onto the opposite contact. This poses a problem with false triggering; You may press a button once but the software may detect 3 or more presses.

Notice how we don't perform any sort of de-bouncing in the code, this is for simplicity and in the future we will tackle this, but for now we're keeping it simple and down to the basics.

One simple way to de-bounce in software is to sample the input multiple times, hardware de-bounce is often proffered but it comes with it's costs. For cheap consumer products more often than not this action is carried in software.

Where do we go from here?

Now that you can manipulate both outputs and inputs; it is time to create something useful. In the next lesson we'll design a full blown bicycle safety light with what we've learnt!

For the next lesson you'll need:

  • 3x General Purpose NPN Transistor ( PN2222, BC337, 3904, etc. Almost any will do )
  • 3x 4k7 Ohm 1/4W Resistors
  • 3x 100 1/4W Resistors ( Could be up to 470 Ohms, or even 1K if high brightness LEDs are used )
  • 1x 10K Ohms 1/4W Resistor (Optional)
  • 1x Tact Switch (Optional)
  • 3x 5mm or 3mm LEDs, Could be all of the same colour or one Red, Green and Blue. Your choice.
  • 1x Breadboard or any other prototyping method of your choice.

Something to download:

The "Using Buttons" project files.

Stay tuned.

Received the MSP430 Launchpad

Posted by on November 24, 2010

I received the launchpad a couple weeks ago, however I’ve been busy so I couldn’t even cook up an example. I do plan on working with it and posting some code here. I have some fun ideas for it (but still waiting on components I ordered…).

Mind you, I still feel strongly about the company TI hired to deal with this product. I would really like to see an explanation from them; but that’s the thing… when you’re a huge company you don’t have to explain anything to anyone, you just do what you want until you go bankrupt and someone gets shot. 😉

What is LaunchPad?

Posted by on June 25, 2010

Bullshit, that’s what it is. They targeted the “Launchpad”  toward the maker/hacker market and yet they don’t provide the according payment methods, these corporate weasels will only take your credit card, tell me how many students actually own a credit card? only the rich kids, who are probably more interested in getting more free money from their parents and living la vida loca than spending their time hacking away on a TI development board alone in their basement.

It just makes no sense whatsoever! they’re trying to get a piece of this huge market by introducing a ridiculously cheap product and yet theres no way anyone outside the US without a CC would be able to get one!.

Therefore TI’s product is as appealing to me as sucking a rusty nail while watching a match of cricket under severe chronic depression! It’s going to end one way and it won’t be pretty.