Using Functions in MSP430
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.
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++)
int main( void )
WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer
P5DIR |= (BIT5); // Set P5.5 as and Output Pin
P5OUT |= (BIT5) ; // P5.5 High
P5OUT &= ~(BIT5) ; // P 5.5 Low
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).