MSP430 Tutorial – LED Blinking Program
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.
// Delay function
unsigned int delay ( unsigned int x)
unsigned int i,j;
for (i = 0; i<= x; i++)
int main( void )
WDTCTL = WDTPW + WDTHOLD;
// Making P5.0 to as output port. Change as required
P5DIR |= BIT0;
P5OUT|= BIT0 ; // P5.0 High
P5OUT&=~BIT0; // P5.0 Low
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.