SHDesigns: Embedded Systems Design, Consulting and Developer Resources Page hits:

Softools WinIDE Tips

Porting DC code:

Add the following includes:

#include "rabbit.h" // ports and global variables specific to the rabbit
#include "dcdefs.h" // this will allow you to use many of the DC function (i.e WrPortI())
These will port many of the DC macros and variables to Softools.

In your main() routine you will need:


That will disable the watchdog timer and enable interrupts. You will also probably need a startTimer() call if you need to use MS_TIMER.

For the PORTA_AUX_IO define in DC, add a call to enableIObus();

For delays, use the delay() function instead of the DC DelayMS().

ASM Code:

See the article on writing asm code: HERE.


Costates are completely non-portable. You will need to emulate them. One way is to use a state machine:

void do_something()
    static int state=0;
    switch (state)
     case 0: // init
        ...init function, i.e. stuff that would be in #GLOBAL_INIT
     case 1: // main function
          ...if you need to wait for some function
          if (device_not ready)
    case 2: // wait for device
         if (device_ready)
    case 3: // device is ready
        ...send data to device

Each of your costates in main would be converted to a function like above. Each nested cofunction would have to have a similar structure.

Then in your main() loop, call the function periodically.

If you have many costates and cofunctions, then moving to a real exec like TurboTask or uCos may be best.

You can get away with no exec at all. ST provides a periodic timer via startTimer(). This will call a user function periodically. This is in effect a background task. One advantage of this is that the background task is more real-time. Add to that a state-machine approach and you can do some efficient task switching.

My Timer B will also call a user function periodically (from once every 15us down to once every 1500 seconds.) That gives you another real-time thread. The lib can be found on my free libs page under: Rabbit Libraries Home Page

Another option is SHDesigns CoExec. This is a free, simple multi-tasking exec for Softools. It is a real task-switcher with less overhead than Costates. Once you use it, you can do much better task switching than DC has. It also emulates some of the DC costate syntax. Ther is also no need for the "cofunc" identifier; all functions are the same and can handle task switches with no special functions types.

Information on CoExec can be found here:

Additional Information: Back to Tips page - SHDesigns Home Page