LED Blinking Example


Download and Install Software


We have finally come to a stage we can write the code for LED blinking. Here is the code that blink the LED on the launchpad.

  1. #include <msp430g2553.h>
  2. // Tutorial LED Blinking from referencedesigner.com
  3.  
  4. // We will use the msp430g255 microcontroller that comes with the launchpad
  5. unsigned int i = 0;
  6.  
  7. void main(void)
  8. {
  9. WDTCTL = WDTPW + WDTHOLD;
  10.  
  11. // Stop watchdog timer.
  12. // Turn off the watchdog timer, otherwise your device will reset. We will learn about it later.
  13.  
  14. // P1DIR is configures the port pin as an output or an input. If it is 1 it is Output.
  15.  
  16. P1DIR = P1DIR | 0x01;
  17.  
  18. // We could also write P1DIR = 0x01
  19. P1OUT = 0x01; // Turn the LED off
  20.  
  21. for (;;)
  22. // Infinite loop
  23.  
  24. {
  25. if ( (P1OUT & 0x01) == 1)
  26.  
  27. P1OUT = 0x00;
  28.  
  29. else P1OUT = 0x01;
  30.  
  31. for(i=0; i< 20000; i++);
  32. // This creates a delay.
  33.  
  34. }
  35. }


The best way to learn about the LED blinking would be to take a look at the youtube. Make sure you do not miss anything in the option.