Co-operative multitasking I think this is the most simple, organized and suitable way to write code for real-time embedded systems. This is simple state machine based model which responds well in real-time. In this case I am using PIC32MX340F512L MCU, you can adopt this code for your favorite microcontroller.
First we write a simple main function where other functions will be called:
// main.c file // add pic32 lib #include // prototype the functions void blinky_init(void); void blinky(void); void button_init(void); void button(void); int main (void) { // initialize the apps blinky_init(); button_init(); // .... // run the app(s) while (1) { blinky(); button(); // .... } } |
In above code snippet we have added processor related libraries, declared the prototypes of the functions which we are going to use and then started the main function. In the main function, we have first initialized the peripherals which we are going to use. In this case only two types, an LED and a push button. The main operations of the peripherals are handled in the blinky(); and button(); functions. Now we look at these functions: (continue reading…)



