Electronic – Embedded system 16×2 lcd user interface

character-lcdembeddedmicrocontrollerpicuser interface

I'm developing a UI for embedded system application.
I have to handle few critical tasks always which are being called in main infinite while() loop.

Program flow enters into sub-menu if key is pressed. Since sub-menu has its own infinite while() loop therefore control can not return back to main loop by on its own.
It makes accessing of critical tasks impossible as long as sub-menu is active.

  • Is there any way to serve tasks in sub loop which are being called in main loop only?
  • One way of accessing is to call them in sub-loop as well. But I don't think its a right approach since UI has 50+ sub-menus and also does sub-loops.

Best Answer

You have not mentioned which MCU you are using but looking at the tag I am assuming you are using PIC MCU. The best solution for your problem is to use FreeRTOS. FreeRTOS is available for PIC18 PIC24 PIC32. You can easily create as many task you want and can also include while(1) inside them.

xTaskCreate( vTask1, "Task 1", 240, NULL, 1, NULL );
xTaskCreate( vTask2, "Task 2", 240, NULL, 1, NULL );
xTaskCreate( vTask3, "Task 3", 240, NULL, 1, NULL );

void vTask1()
{
 for(;;)
 {
    PORTDbits.RD0 = 1;
    vTaskDelay( 1000 / portTICK_RATE_MS );
    PORTDbits.RD0 = 0;
    vTaskDelay( 1000 / portTICK_RATE_MS );

 }
}

same you can do for other task. Now all you need to do is run scheduler

vTaskStartScheduler();