MSP430 Embedded Programming Tutorial TUTORIAL


Using Functions


Using functions in MSP430 is no different than using the functions in normal C programming. You should keep in mind that the varialbles that can be passed to the fuctions should be only those that can be allowed.

Functions Example


The following program implements a functions that implements a delay. The parameters to the function is the amount of the delay in milliseconds. The exact amount of the delay will depend upon the clock frequency as well.

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


}


int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P5DIR |= (BIT5);
while (1)
{
P5OUT |= (BIT5) ; // P5.0 High
delay(100);
P5OUT &= ~(BIT5) ; // P 5.0 Low
delay(100);
}
}



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