??? 03/06/09 14:50 Read: times |
#163160 - enum + switch() ... case ... break Responding to: ???'s previous message |
Walter Adrián Quiroga said:
Hi everybody, I need if somebody could help me, I need some example in C of Finite State Machine to apply in 8052. Let obj be the object you want to control (e.g., a communication protocol). I normally write my code this way: /// object FSM's states enum OBJ_STATES { OBJ_STATE_INIT, OBJ_STATE_1, OBJ_STATE_2, ... }; /// object FSM container struct obj_fsm { enum OBJ_STATES state; ///< current state char var1; ///< variable 1 char var2; ///< variable 2 ... }; /// actual object FSM static struct obj_fsm obj_fsm; /// initialize object void init_obj (void) { obj_fsm.state = OBJ_STATE_INIT; } /// update object FSM state void update_obj (void) { switch (obj_fsm.state) { case OBJ_STATE_INIT: ... obj_fsm.state = OBJ_STATE_1; break; case OBJ_STATE_1: ... } } I've been using this scheme for a few years and I find it flexible and very easy to follow and understand what I meant the FSM to do even after long time. |
Topic | Author | Date |
FSM Finite State Machine | 01/01/70 00:00 | |
Clarify | 01/01/70 00:00 | |
FSM Finite State Machine | 01/01/70 00:00 | |
enum + switch() ... case ... break | 01/01/70 00:00 | |
FSM | 01/01/70 00:00 | |
no struct + transactions | 01/01/70 00:00 | |
Thank you So Much![]() | 01/01/70 00:00 | |
SMC - The State Machine Compiler | 01/01/70 00:00 |