Prerequisites:-
The prerequisite for this program you should have knowledge of Simple LCD interfacing on ARM LPC2148. You can visit this post to get the program, algorithm about LCD interfacing.
Introduction:-
In this post, We will be dealing with RTOS(Real-time Operating System) Program to switch the tasks based on the priorities.At first the OS is initialised with Task1 as highest priority and later task2 is created. For simplicity only two taskes are used in this program.Before completion of Task1 the priority of task2 is increased.Similarily in task2 before completion the priority of task1 is set to high.It continues like this Task1 —-> Task2 —-> Task1 —> Task2 and so on.Task1 will display the message on first line of LCD and Task2 will display message om second line of LCD.
Algorithm:-
- Start.
- Declare Task1,Task2.
- Call the task1.
- Assign highest priority to task1,next priority to task2.
- Wait till the completion and jump to task2.
- Loop continues.
- End.
Code:-
#include#include #include /*---------------------------------------------------------------------------- * Function Prototypes *---------------------------------------------------------------------------*/ void comm(void); void writeData(void); void data(void); void lcd_initialize(void); void writeCommand(void); void clr_display(void); void delay(unsigned int); void first(void); void second(void); /*---------------------------------------------------------------------------- * Global Variable declaration *---------------------------------------------------------------------------*/ unsigned char temp1; unsigned long int temp,r=0; unsigned char *ptr; unsigned char data1[] = "RTOS",data2[] = "ABHIJEET ABHAY"; OS_TID t1,t2; __task void task1(void); __task void task2(void); int main() { os_sys_init(task1); //starts with task1 while(1); } /*---------------------------------------------------------------------------- * Task 1 - High Priority - *---------------------------------------------------------------------------*/ __task void task1(void) { t2=os_tsk_create(task2,0); t1=os_tsk_self(); while(1) { IO0DIR = 0x000000FC; //configure o/p lines for lcd lcd_initialize(); delay(3200); clr_display(); //lear lcd delay(3200); temp1 = 0x80; //Display starting address of first line comm(); ptr = data1; while(*ptr!='\0') { temp1 = *ptr; data(); ptr ++; } delay(1000000); clr_display(); delay(3200); os_tsk_prio(t2,5); os_tsk_prio(t1,2); } } __task void task2(void) { while(1) { IO0DIR = 0x000000FC; lcd_initialize(); delay(3200); clr_display(); delay(3200); temp1 = 0xC0; //Display starting address of second line comm(); ptr = data2; while(*ptr!='\0') { temp1 = *ptr; data(); ptr ++; } delay(1000000); clr_display(); delay(3200); os_tsk_prio(t1,5); os_tsk_prio(t2,2); } } void delay(unsigned int r1) { for(r=0;r
Download the Code:To Download the Complete Project click on the link below:
Nice article.Love you admin for posting this.Life saver…!