Home > Uncategorized > Using Functions in MSP430

Using Functions in MSP430

February 28th, 2011 Leave a comment Go to comments

Functions in MSP430 are not very different from the functions in normal C programming. Note that the variables that can be passed to the functions should be only those that can be allowed.

Functions Example in MSP430

The following complete example has a functions that implements a delay. The parameters to the function delay() is the approximate amount of the delay in milliseconds. The exact amount of the delay will depend upon the clock frequency of your hardware.

 

#include
unsigned int delay(unsigned int ms)
{
// i and j are Local variables
unsigned int i, j;
for (i = 0; i <= ms; i++)
{
for (j = 0; j<=255; j++)
{
}
}
return 0;

}

int main( void )
{

WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer
P5DIR |= (BIT5); // Set P5.5 as and Output Pin
while (1)
{
P5OUT |= (BIT5) ; // P5.5 High
delay(100);
P5OUT &= ~(BIT5) ; // P 5.5 Low
delay(100);
}
}

 

Copy paste this example and see its effect on oscilloscope or an LED ( if there is one hooked to the IO port in this example).

Categories: Uncategorized Tags:
  1. No comments yet.