On 10/10/2011 I updated my state machine demo project. Although I thought the project was complete at its original posting, I later realized it could be cleaned up and slightly expanded. Sorry for any inconvenience.
This project was an exercise prompted by my study of two books: "MSP430 State Machine Programming" by Tom Baugh and "Practical UML Statecharts in C/C++" 2nd ed. by Miro Samek. I am just a microcontroller hobbyist, but I have been looking for a general approach to embedded programming suitable for the small AVR and MSP430 chips I like to use.
Some time ago I built a traffic lights demo using 4AVROS and found it nice to work with. (Actually it was the only AVR RTOS I could get to work!) However, I did not want to try to port it to the MSP and there were certain limitations to worry about. Then I discovered Baugh's book. This book taught me more about effective micro programming with C than any other book I have found. It shows how the state machine approach allows multi-thread programs without using an RTOS. (Baugh is also a master at minimizing current draw.)
The only down side to Baugh's approach is that it can get a bit hard to follow the sequence of state execution in the code. So I decided to look into more formal state machine software. That is where Samek's book came in. Although that book covers a system for hierarchical state machines, I grabbed the comparatively simple flat state machine implemenation from Chapter 3. This allows me to keep better track of things in the code.
This demo project uses the overall program organization of Baugh, but with the flat state machine structure of Samek. It was not written for minimal current draw, but it is the first project I've done with an AVR mega that uses the sleep capabilities of the AVR. The processor sleeps in power down mode until awoken by either a system tick generated by the watchdog timer or a port pin interrupt.
At this point I think I've found the general approach to micro programming I was looking for, at least for projects that don't need very low current draw. In those cases I would revert to the "naked" state machines of Baugh.
[moderator: I *assume* this is the project being referred to here: https://www.avrfreaks.net/index.p... - I sure wish people would include links in future - no one here is psychic]