Delay for MSP430

March 12, 20132 comments Coded in C for the TI MSP430

This code contains the functions for configure internal oscillator and delay functions for milli second and microsecond

void configureClocks();
void delay_ms(unsigned int ms);
void delay_us(unsigned int us);

void configureClocks()
{
     WDTCTL = WDTPW + WDTHOLD;          // Stop WDT
     BCSCTL1 = CALBC1_1MHZ;
     DCOCTL = CALDCO_1MHZ;

 }

void delay_us(unsigned int us)
{
	while (us)
	{
		__delay_cycles(1); // 1 for 1 Mhz set 16 for 16 MHz
		us--;
	}
}

void delay_ms(unsigned int ms)
{
	while (ms)
	{
		__delay_cycles(1000); 1000 for 1MHz and 16000 for 16MHz
		ms--;
	}
}

Comments:

There are no comments yet!


Sorry, you need javascript enabled to post any comments.