FreeRTOS – LPC2148 (LCD Scroll and LED Blinking)

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 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.

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.

  1. LED blinking
  2. 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,

                                  const signed portCHAR * const pcName,

                                  unsigned portSHORT usStackDepth,

                                  void *pvParameters,

                                  unsigned portBASE_TYPE uxPriority,

                                  xTaskHandle *pxCreatedTask );

 

  • 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]

FreeRTOS LCD Interfacing with LPC2148

 

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader Tutorials
5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
6
0
Would love your thoughts, please comment.x