Home > Uncategorized > MSP430 Tutorial – LED Blinking Program

MSP430 Tutorial – LED Blinking Program

February 28th, 2011 Leave a comment Go to comments

We will extend what we have learned so far to write something visibly interesting. Let us write a program that will make an LED hooked to an IO port of MSP430 blink. We will need to write a simple delay function. The main program will call the delay function between LED on and LED off.

Go ahead and paste the following code in the IAR embedded system. As before, replace the msp430x14x.h and the IO pin corresponding to your hardware. In this particular example there is an LED connected to Port P5.0. If you have an LED connected to, for example P2.3, then replace statement P5DIR |= BIT0 with P2DIR |= BIT3 and similarly the P5OUT lines.

#include
// Delay function
unsigned int delay ( unsigned int x)
{
unsigned int i,j;
for (i = 0; i<= x; i++)
{
for(j=0;j<=1000; j++)
;
}
return 0;
}

int main( void )
{

WDTCTL = WDTPW + WDTHOLD;

// Making P5.0 to as output port. Change as required
P5DIR |= BIT0;
while(true)
{
P5OUT|= BIT0 ; // P5.0 High
delay(100);
P5OUT&=~BIT0; // P5.0 Low
delay(100);
}

return 0;
}

If we run this program freely ( after compiling hit F5), it will make the LED go on and off in an infinite loop. You may change the duration of the blink by changing the parameter of the delay(100).

In the next section we will see how to use a port pin of MSP430 as an input pin.

Categories: Uncategorized Tags:
  1. No comments yet.