23EC403-EMBEDDED C++
NAME: SOULWIN RAJ S
REGESTER NO:727723EUEC190
CLASS: II-ECE-‘A’
Interfacing LED AND LCD with LPC2148 Using
FreeRTOS: LED Blinking and LCD Scrolling
INTRODUCTION:
In embedded systems, Real-Time Operating Systems (RTOS)
play a crucial role in managing multiple tasks efficiently. Unlike
traditional microcontroller programming, where tasks run
sequentially, RTOS allows the execution of multiple threads (tasks)
based on their priority levels. The task scheduling in FreeRTOS
ensures that the LCD scrolling task, which has a higher priority,
executes more frequently compared to the LED blinking task. This
demonstrates how task prioritization in FreeRTOS enables better
control over time-sensitive operations in embedded systems.
WORKING PRINCIPLE:
The FreeRTOS-based LED and LCD interfacing with LPC2148
works on the principle of task scheduling and prioritization. FreeRTOS
is a real-time operating system that manages multiple tasks
efficiently by allocating CPU time based on their priority.
Key Working Principles:
1. Task Creation:
o Two tasks are created using FreeRTOS:
LED Blinking Task (Lower priority)
LCD Scrolling Task (Higher priority)
o Each task is assigned a priority, ensuring that the LCD task
gets more execution time than the LED task.
2. Task Scheduling (Preemptive Kernel):
o FreeRTOS manages the tasks using a preemptive
scheduling algorithm.
o Since the LCD scrolling task has a higher priority, it runs
whenever it is ready, preempting the LED task if needed.
o The LED task runs only when the CPU is idle or when the
LCD task is not executing.
3. Task Execution:
o LED Blinking Task:
Uses GPIO to toggle an LED at a fixed delay (e.g.,
500ms).
Runs in a loop with a delay, allowing other tasks to
execute in between.
o LCD Scrolling Task:
Uses the LCD interface to scroll text across the
display.
Runs continuously but gives CPU time to other tasks
as needed.
4. FreeRTOS Delay Mechanism:
o The TaskDelay() function is used to introduce delays,
allowing the RTOS to switch between tasks efficiently.
o This prevents blocking the CPU and ensures that other
tasks get executed.
COMPONENTS REQUIRED:
1. Microcontroller & Development Board:
LPC2148 Microcontroller (ARM7-based)
LPC2148 Development Board
2. Display Module:
16x2 Alphanumeric LCD Module
10KΩ Potentiometer (for LCD contrast adjustment)
3. LED & Resistors:
LED (Light Emitting Diode)
330Ω Resistor (current limiting for LED)
4. Power Supply:
5V DC Power Supply
Battery/USB Power Adapter
5. Connectivity Components:
Push Buttons (for reset and control if needed)
Jumper Wires (Male-to-Male, Male-to-Female)
Breadboard (for prototyping)
6. Programming & Debugging Tools:
USB-to-Serial Converter (for flashing the firmware)
Keil µVision IDE (for coding and compilation)
Flash Magic (for programming the LPC2148)
7. Software & Libraries:
FreeRTOS Kernel Files
LPC2148 Peripheral Libraries
BLOCK DIAGRAM:
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);
}
CIRCUIT:
OUTPUT:
RESULT:
After successfully interfacing the LED and LCD with LPC2148 using
FreeRTOS, the system exhibits the following behavior:
1. LED Blinking Task (Lower Priority):
o The LED toggles ON and OFF at a fixed interval (e.g., every
500ms).
o Since this task has a lower priority, it executes only when
the higher-priority task is idle.
2. LCD Scrolling Task (Higher Priority):
o The 16x2 LCD continuously scrolls a predefined message.
o This task, having a higher priority, preempts the LED
blinking task whenever necessary.
3. Task Scheduling in Action:
o FreeRTOS ensures that the LCD scrolling task runs more
frequently than the LED blinking task.
o The LED task executes in the remaining CPU time without
interrupting the LCD task.
CONCLUSION:
The successful execution of both tasks with different priorities
demonstrates task scheduling and real-time execution using
FreeRTOS on the LPC2148 microcontroller. This proves that FreeRTOS
efficiently manages multiple tasks and ensures smooth task
execution based on priority levels.