This is one you'll find in pretty much every MSP430 tutorial or example, but yet it continues to bite people. At power up, the processor's watchdog timer, a device which resets the processor if it thinks that the firmware has locked up or entered an infinite loop, is enabled. This means that after booting, you only have a few thousand processor cycles to "service" the watchdog, which is the technical term for telling it that your application is still making progress.
The most common error to make with respect to the watchdog timer is simply ignoring it. If this happens, the device will reset itself over and over, as the watchdog timer expires after each boot.
Disabling the watchdog timer at bootup is the simplest way to deal with this. For "real" applications you likely want to configure and reenable the watchdog, but for learning it's OK to simply disable it and leave it disabled. Fortunately, disabling the watchdog is easy to do, and accomplished with this single line of code:
Code:
WDTCTL = WDTPW | WDTHOLD;
WDTCTL is the watchdog control register. WDTPW is a special constant, the "watchdog timer+ password". Any value written to the watchdog control register without this password will be ignored and trigger an error condition, so make sure you include it when manipulating the timer. The WDTHOLD bit disables the watchdog timer.