Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


newbie -- writing lcd driver

Posted by Nobody/Anonymous on April 4, 2006
I was given a HD44780 LCD module a few months ago and took interest in writing a driver for it when I was kicking the tires on FreeRTOS. Below is my approach, it's the first driver I've written and I was seeking comments. (I should say that I'm using FreeRTOS in pre-emptive mode with several tasks running. At this point everything is an exercise in programming, just to learn the basics.)

I first wrote a few core routines to manage the control and data lines out of an ATMega32. I employed a lot of macros to do the device/OS specific code (like PORT output, delays, critical sections, etc.) in case I wanted to use this on another platform. All the device/OS macros are kept in a lcd_port.h file. Since the LCD control signals are time sensitive, I protected each LCD command in a critical block. This way the driver is ensured that it can complete the current LCD command.

The next step was writting routines like lcd_char, lcd_string, etc. Since these are likely to change from application to application, I placed them in another .C file. In addition, since the eventual code will possibly be running in a pre-emptive OS, I placed mutex code in each LCD routine. In short, each LCD routine grabs the mutex while it's running, and gives it up when it's done, ensuring sequential text output. At this point, I have a collection of routines that I can easily use to display text on the LCD as well as a somewhat easy-to-port lower level driver.

The final step is integrating this into FreeRTOS. As an RTOS newbie, I'm a little unsure of how to continue. I'm assuming the mutex and critical sections place this application in the soft-realtime space. My tenative next step is to create an LCD-output task in FreeRTOS that handles output. This way the other tasks can fire off a message and continue working if needed. (I'm thinking that this approach would also minimize priority inversions.)

This is getting a little long winded, so I'll wrap it up here. As a newbie, is my approach sound? Any suggestions or glaring issues?


-- Joe

RE: newbie -- writing lcd driver

Posted by Nobody/Anonymous on April 4, 2006
Take a look at the PC port which you can run using Open Watcom. This uses a scheme whereby a task blocks on a queue. When a task want to print a message it sends a pointer to the message on said queue - waking the task which then reads and displays the message.

This way the mutual exclusion is handled by the fact that there is only one task that is permitted to access the hardware - in this case the vdu rather than an lcd - but the principal is the same.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner