Delay for 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--;
}
}