:: Home :: Code Snippets :: Drivers :: Projects :: About ::
 Main Menu
  Home
  Code Snippets
  About

 Open Drivers
 PIC32 mcompat - PIC32 mcompat
 _build - Embedded build information
 qTask - Queued Task Manager
 EA-DOGM - LCD Display Driver

 Open Projects
 oLogic - Oscilloscope Logic Viewer
 oLogic 1.4 - NEW Logic Viewer
 SSX32 - Serial Servo Driver



 Sources
Prototyping
  PicStuff
  Sparkfun

Equipment
  Saelig
  Tequipment

Supply House
  Jameco
  Mouser
  Digikey
  Allied Electronics
  Clearwater Technologies

Miscellaneous
  BCM
  N34D Blog

Slice - Slice Manager, aka State Machine.

A macro wrapped up state machine

 Code Snippet
/vhost/mculabs/snippet_db/slice/slice.h
    1 // slice manager
    2 // execute slices of a pie
    3 
    4 // in this example, one 1 slice of my_large_task gets executed every loop
    5 
    6 // define some macros for use as a state machine
    7 #define mDefinePie unsigned int8
    8 #define mSliceManager(slice,n)  slice++; if (slice > n) { slice = 1; } switch (slice)
    9 #define mOrderSlice(sid,fn)     case sid: { fn; break; }
   10 #define mPieIni(slice)          slice = 0;
   11 
   12 
   13 
   14 // example code:
   15 
   16 mDefinePie myPie;
   17 
   18 
   19 void slice_ledOn(void) {
   20   mPwrLed_on();
   21 }
   22 
   23 void slice_ledOff(void) {
   24   mPwrLed_off();
   25 }
   26 
   27 
   28 void my_large_task(void)
   29 {
   30   // manage 2 slices of the pie
   31   mSliceManager(myPie,2)
   32     {
   33     // define the order of the slices, (constant, function)
   34     mOrderSlice(1,slice_ledOn());
   35     mOrderSlice(2,slice_ledOff());
   36     }
   37 
   38 }
   39 
   40 
   41 void main(void)
   42 {
   43   mPieIni(myPie);
   44 
   45   while(1)
   46     {
   47     my_large_task();
   48     }
   49 }






:: Home :: Resources :: PIC Microcontrollers ::
:: 10F :: 12F :: 16F :: 18F :: 24F :: 24H :: 30F :: 33F ::
(C) Copyright 2009 mculabs.com - contact: info@mculabs.com
0.093235969543457