// define some task ID's #define TASKID_LEDBLINK 1 #define TASKID_COUNT 2 // define a pie (basically name of a state machine) qDefinePie pieBlinkLed; // how many uSeconds in a tick? // with this test, pic has 10mhz xtal with x4 PLL #define QTASK_TOCK 500 #include "qtask.c" void slice_ledOn(void) { mPwrLed_on(); } void slice_ledOff(void) { mPwrLed_off(); } void task_blink_led(void) { // manage slices of the pie mqSliceManager(pieBlinkLed) { // define the order of the slices, (constant, function) mqOrderSlice(1,slice_ledOn()); mqOrderSlice(2,slice_ledOff()); } // we need to define what the last slice was (this resets slice counter) mqLastSlice(pieBlinkLed,2); } void task_count(void) { c++; } void main(void) { // initialize the queued task system qTaskInitialize(); // set task parameter ( task id, how many tics) mqTaskSetTmr(TASKID_LEDBLINK, 1000000); mqTaskEnable(TASKID_LEDBLINK); mqTaskSetPri(TASKID_LEDBLINK, QTPRI_HIGHEST); // set highest priority mqTaskSetTmr(TASKID_COUNT, 50000); mqTaskEnable(TASKID_COUNT); mqTaskSchedulerEnable(); // turn on the task scheduler enable_interrupts(GLOBAL); // since scheduler runs on int, must enable global // initialize the blink led pie (state machine) mqPieIni(pieBlinkLed); while(1) { // ** your main program here / or run all in task manager ** // some tasks to manage mqTaskManager() { // tell it what function to execute per task id mqTaskFunction(TASKID_LEDBLINK, task_blink_led()); mqTaskFunction(TASKID_COUNT, task_count()); } } }