1 / 3

main ()

main (). int main(void) { unsigned int buttons, dir , mode, sm_code , mS ; system_init (); /* Initialize Cerebot MX7ck */ while(1) /* Infinite application loop */ { buttons= read_buttons (); decode_buttons (buttons, & dir , &mode);

ifama
Download Presentation

main ()

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. main () intmain(void) { unsigned int buttons, dir, mode, sm_code, mS; system_init(); /* Initialize Cerebot MX7ck */ while(1) /* Infinite application loop */ { buttons=read_buttons(); decode_buttons(buttons, &dir, &mode); sm_code=sw_fsm(dir, mode); output_sm_code(sm_code); mS=delay_calc(mode); hw_msDelay(mS); } return(1); } /* End of main */

  2. decode_buttons() void decode_buttons(unsigned int buttons, unsigned int *dir, unsigned int *mode) { switch (buttons) { case BTN1 : *dir = CW; *mode = HS; break; [...] } // case } // decode_buttons dir and mode are pointer variables local to decode_buttons

  3. sw_fsm() unsigned intsw_fsm(unsigned intdir, unsigned int mode) { enum {S0=0, S0_5, S1, S1_5, S2, S2_5, S3, S3_5}; static unsigned intpstate; const unsigned intsm_code[] = {0x02, 0x0A, [...] }; switch (pstate) // Next State Logic { case S0: if (dir==CW) { if (mode == HS) pstate= S0_5; else // FS pstate = S1; } else // CCW [...] break; [...] No magic numbers! 

More Related