I'm trying to flash an LED on a TI MSP430 Launchpad board. I have two pieces of code. One works, while the other doesn't. The only difference is the inclusion of the volatile keyword in working version. Why is this keyword needed for the program to execute?
This code works...
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure Port Directions
P1DIR |= 0x01; // 0000 0001
volatile unsigned int i;
for(;;)
{
P1OUT ^= 0x01; // Set P1.0 LED on
for (i = 20000; i > 0; i--); // Delay
}
}
While this code does not...
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure Port Directions
P1DIR |= 0x01; // 0000 0001
unsigned int i;
for(;;)
{
P1OUT ^= 0x01; // Set P1.0 LED on
for (i = 20000; i > 0; i--); // Delay
}
}