[TUT] [SOFT] [HARD] [C] State Machines and Function Pointers

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone!

I recently did a PS/2 project where I had to make a big state machine to handle communications. I decided to use function pointers and was pretty happy with the result. Knowing that many AVR beginners are maybe not familiar with C intricacies, I decided to write a very approachable tutorial about state machines and function pointers:

http://codeandlife.com/2013/10/06/tutorial-state-machines-with-c-callbacks/

It starts with a few simple examples of implementing a state machine with ifs or a switch, and then explains function pointers (also showing generated assembly instructions :^) and how the work, and finally shows example code to implement a simple state machine with function pointers.

I also included a more advanced sample in the end, I'm planning to do a PS/2 comms tutorial in future so maybe more about that in the future.

Attachment(s):