I read the Evil Mad Scientist Labs project "A pumpkin that sleeps like a Mac". This inspired me to build up an LED project to light my jack-o-lantern. Their project uses an ATtiny2313 and I didn't have time to order parts. But I did have some TI MSP430 LaunchPad boards that I hadn't even opened yet.
So I installed an IDE and ported the code from AVR to MSP430.
The MSP430 has a timer counter with a PWM function, but rather than learn how to program TI's timer, I just converted the code to a simple, brute force PWM function in software.
Another change I made to the code was to change their algorithm's constants into variables. This allowed me to easily try different values to get the blinking effect I wanted without a lot of re-compiles. I could just pause the debugger, change a value, hit continue to see the effect. Once I had an blink that I liked, I put the numbers into the initialization of the variables and programmed the MSP430 processor.
The basic blinking algorithm is still as Evil Mad Scientist Labs originally designed it. I just tweaked some code details.
One thing I learned is that the IAR IDE is configured by default to disable downloading the code to the target system when you press the "Download and Debug" button. Note that the button right next to it is "Debug without Downloading". Why there is such an option, I don't know. They should grey out that icon, or change the tool tip. It sure wasted a bit of my time figuring that problem out. Anyway, the fix is under Project > Options > Debugger. Change the Driver pulldown from "simulator" to "FET Debugger".
Here is the code:
Some notes on the circuit.
The MSP430 is rated for VCC of 2.2 to 3.6 volts. I used two AA which gives a nominal 3V VCC.
The MSP430 outputs can drive about 25mA. I used some 2.2V red LEDs rated for 20mA, so I could probably have driven the LED directly. That would be running both the MSP430 and the LED at their limits, which isn't good for reliability nor battery life. Instead, I used 180 ohm resistors which gives about 4.5mA of current to the LED. I hooked up two LEDs, each on its own pin. The code as written drives pins P1.7 and P1.6. This seems to be bright enough to light the inside of a pumpkin sitting on a porch.