Hi Guys…….. Today i came with new tutorial (FreeRTOS LCD Interfacing with LPC2148). Before that you should know How to interface and with LPC2148.
Post Contents
Prerequisites
Before we will start i would suggest you to read these topics. Then only you can understand this strongly. If you already know, please go ahead.
- How to port FreeRTOS with Keil
- RTOS Tutorial
- LCD Interfacing with LPC2148
- LED Interfacing with LPC2148
FreeRTOS LCD Interfacing with LPC2148
Introduction
We already know why we are using RTOS. Because we can develop multi threads in RTOS whereas without RTOS we cant. Create the RTOS project. Here I’ve created two threads.
- LED blinking
- LCD scroll
Connections
LED Blinking
LED is connected into Port 0.8 to P0.15. This thread will blink the LEDs.
LCD Scroll
LCD is connected into Port 1.
Before that, FreeRTOS has many API. Here we are going to use API for Task creating and Delay.
FreeRTOS APIs
xTaskCreate() API
This FreeRTOS API is used to create a task. Using this API we can create more number of tasks.
portBASE_TYPE xTaskCreate ( pdTASK_CODE pvTaskCode,
|
pvTaskCode
: a pointer to the function where the task is implemented. (Address of the fuction)pcName
: given name to the task. This is useless to FreeRTOS but is intented to debugging purpose only.usStackDepth
: length of the stack for this task in words. The actual size of the stack depends on the micro controller.pvParameters
: a pointer to arguments given to the task.uxPriority
: priority given to the task, a number between 0 and MAX_PRIORITIES – 1.pxCreatedTask
: a pointer to an identifier that allows to handle the task. If the task does not have to be handled in the future, this can be leaved NULL.
VtaskDelay() API
We are using this API for delay purpose.
Now go through the code.
CODE
#include<FreeRTOS.H> #include<task.h> #define bit(x) (1<<x) void lcd(void *); void led(void *); void lcd_init(void); void cmd(unsigned char a); void dat(unsigned char b); void show(unsigned char *s); void lcd_delay(void); void lcd_init() { cmd(0x38); cmd(0x0e); cmd(0x01); cmd(0x06); cmd(0x0c); cmd(0x80); } void cmd(unsigned char a) { IO1CLR=0xFF070000; IO1SET=(a<<24); IO1CLR=bit(16); //rs=0 IO1CLR=bit(17); //rw=0 IO1SET=bit(18); //en=1 lcd_delay(); IO1CLR=bit(18); //en=0 } void dat(unsigned char b) { IO1CLR=0xFF070000; IO1SET=(b<<24); IO1SET=bit(16); //rs=1 IO1CLR=bit(17); //rw=0 IO1SET=bit(18); //en=1 lcd_delay(); IO1CLR=bit(18); //en=0 } void show(unsigned char *s) { while(*s) { dat(*s++); } } void lcd_delay() { unsigned int i; for(i=0;i<=2000;i++); } int main() { IO0DIR=IO1DIR=0xffffffff; lcd_init(); xTaskCreate(lcd,"lcd scroll",1000,0,1,0); xTaskCreate(led,"led blinking",1000,0,1,0); vTaskStartScheduler(); } void lcd(void *s) { cmd(0x80); show("Embetronicx.com "); while(1) { cmd(0x18); vTaskDelay(1); } } void led(void *s) { while(1) { IO0SET=0xff00; vTaskDelay(1); IO0CLR=0xff00; vTaskDelay(1); } }
OUTPUT
If you have any doubt in this please ask us by commenting below. Thank you.