MSP430 - Flash LED

The next step is to insert two delays in order to slow down the LED flash rate.

A 16-bit unsigned integer can represent a value from 0 to 65535.

While this is sufficient for our simple delay, we will use a 32-bit unsigned integer in case we need a longer delay at some point in the future.

32-bit unsigned long integer is good to 4,294,967,295

a bit more than we will ever need!


Here is the code:

Code:
// Getting Started Tutorial - LED Flash
// 2013.04.19 - MrChips

#include "io430.h"

void init(void)
{
  P1OUT = 0;
  P1DIR = 0xFF;
}

void delay(unsigned long d)
{
  unsigned long i;
  for (i = 0; i < d; i++);
}

void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  init();
  while (1)
  {
    P1OUT_bit.P0 = 1;
    delay(25000);
    P1OUT_bit.P0 = 0;
    delay(25000);
  }
  
}
The duration of each delay statement is about 250ms, i.e. the LED is on for 250ms and off for 250ms. The total period is 500ms, i.e. the LED flashes at a rate of two times each second.

Blog entry information

Author
MrChips
Views
1,094
Last update

More entries in General

More entries from MrChips

Share this entry

Top