This article is a continuation of the Series on FreeRTOS and carries the discussion on FreeRTOS and its usage. The aim of this series is to provide easy and practical examples that anyone can understand. Today I came up with a new tutorial (FreeRTOS LCD Interfacing with LPC2148).
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 to Port 1.
Before that, FreeRTOS has many APIs. 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 tasks.
portBASE_TYPE xTaskCreate ( pdTASK_CODE pvTaskCode,
|
pvTaskCode
: a pointer to the function where the task is implemented. (Address of the function)pcName
: given name to the task. This is useless to FreeRTOS but is intended for debugging purposes only.usStackDepth
: length of the stack for this task in words. The actual size of the stack depends on the microcontroller.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 handling the task. If the task does not have to be handled in the future, this can be left NULL.
VtaskDelay() API
We are using this API for delay purposes.
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
[You can check the below image]
You can also read the below tutorials.
Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related stuff! also, I wanted to deliver you the same as much in a more straightforward way with more informative content. I generally appreciate learning by doing, rather than only learning. If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!