Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Tutorial: HD44780 Display Driver With NXP MCUXpresso SDK

DZone's Guide to

Tutorial: HD44780 Display Driver With NXP MCUXpresso SDK

Check out this tutorial on how to use a character display with the NXP MCUXpresso IDE and SDK.

· IoT Zone ·
Free Resource

Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More

In the age of high-resolution graphical LCDs, using a character display might look like a bit anachronistic. But these displays provide a lot of value for me as they are robust and are available in different shapes and numbers of lines. And such a character display can be a better solution for an industrial application.

hd44780 display with NXP FRDM-KW41Z Board

hd44780 display with NXP FRDM-KW41Z Board

In the HD44780 2×16 Character Display for Kinetis and Freedom Board, I have used the Processor Expert to generate the driver. In this article, it is about using that driver with the NXP MCUXpresso IDE and SDK.

Outline

This article describes how to use HD44780 (or compatible) character displays with the NXP MCUXpresso SDK and the Eclipse-based MCUXpresso IDE. With the help of this article, you should be able to use these kinds of displays for any NXP MCUXpresso SDK project.

The HD44780 is a commonly used character display controller that can be found in many variants. Just watch out that your display is using the same logic levels (3.3V or 5V) as the microcontroller you want to use with it.

The driver used here has the following features:

  • Static configuration of the driver using configuration header files
  • Support for 1, 2, 3, or 4 line displays
  • 4bit or 8bit GPIO data bus
  • Support for reading data from the display
  • Configurable delays to work with ‘non-standard’ displays
  • Variable character width setting
  • Configurable pin assignments
  • Support for custom character sets
  • Special hardware abstraction to work with any SDK and version

To see some example projects, see the links at the end of the article.

Software/Tools

For reference, I have used the following software and tools in this article:

mcuxpresso ide 10.3.0

  • NXP FRDM-KW41Z Board
    • MCUXpresso SDK for FRDM-KW41Z v2.2.0:sdk for frdm-kw41z

    sdk for frdm-kw41z

  • McuOnEclipse driver library
  • Project

    The first step is to create an 'empty' project with these default settings:

    create new project

    create new project

    Clone the GitHub Repository or download the files as a zip file and place them into the project:

    mculib with hd44780 files

    mculib with hd44780 files

    The HD44780 files are in a dedicated folder with pin files for each GPIO pin. The configuration header files are located in the ‘config’ folder.

    Compiler Settings

    The next step is to tell the compiler where to find the header files. Add the following lines (copy-paste) to the compiler and include path settings. This will enable the project to use much more than discussed here (e.g. Segger RTT, SystemView, Percepio Trace, FreeRTOS, …).

    ../McuLib/config
    ../McuLib/config/fonts
    ../McuLib/src
    ../McuLib/HD44780
    ../McuLib/FreeRTOS/Source/include
    ../McuLib/FreeRTOS/Source/portable/GCC/ARM_CM4F
    ../McuLib/SEGGER_RTT
    ../McuLib/SEGGER_Sysview
    ../McuLib/TraceRecorder/config
    ../McuLib/TraceRecorder/include
    ../McuLib/TraceRecorder/streamports/Jlink_RTT/include

    mculib includes

    mculib includes

    MCULib Configuration

    The main library configuration is in config/McuLibconfig.h. This header file allows a very flexible configuration of the drivers, so it can adapt to many MCUs and cores.

    The first thing is to check the CPU/Core setting. As the MCU on the FRDM-KW41Z is an ARM Cortex-M0+, the following settings are used:

    core configuration

    core configuration

    cortex m identification

    cortex m identification

    The next thing to check/configure is that the SDK used. In my example, I’m using the NXP MCUXpresso SDK V2.2.0:

    sdk used

    sdk used

    Pin Muxing

    The driver uses normal GPIO pins: you need at least four data GPIO pins with an enable (E) and RS pin (see HD44780 2×16 Character Display for Kinetis and Freedom Board). The easiest way to configure the pins is using the NXP MCUXpresso Configuration tools integrated with the MCUXpresso IDE:

    configured lcd pins in mcuxpresso configuration tools

    configured lcd pins in mcuxpresso configuration tools

    Configure the pins inside the pin configuration header files:

    data pin configuration

    data pin configuration

    Note that, for the above, I could directly use the information from the baord.h header file. In order to not add yet another dependency, the pin GPIO/Port setting and pin number is kept in a dedicated header file for each pin for better portability.

    Configure all pins depending on your hardware connections (for example, RS, RW, E1, E2, number of data pins).

    LCD Configuration

    The LCD is configured in config/McuHD44780config.h. Here, things are the number of character lines, the number of data pins or readability, or timing of the display can be configured:

    hd44780 configuration

    hd44780 configuration

    Driver Initialization

    In the application code, the used drivers have to be initialized. The HD44780 uses the McuWait driver, which has to be initialized too.

    Because every display might be different and might need some time to power up, I recommend adding a delay before accessing the display.

    McuWait_Init();
    McuWait_Waitms(50); /* give hardware time to power up */
    McuHD44780_Init();


    It might need 50 ms, 100 ms, or even more, so you have to try this out. The McuHD44780_Init() will initialize all the pins and the display. After that, the display can be used.

    Using the Driver

    There are functions to clear the display, to write to it, or to enable things like blinking cursor. The example code below clears the display and writes the data/time:

    McuHD44780_Clear();
    {
      DATEREC date;
      TIMEREC time;
    
      buf[0] = '\0';
      McuTimeDate_GetTime(&time);
      McuTimeDate_AddTimeString(buf, sizeof(buf), &time, (uint8_t*)"hh:mm.ss,cc");
      McuHD44780_WriteLineStr(1, (char*)buf);
    
      buf[0] = '\0';
      McuTimeDate_GetDate(&date);
      McuTimeDate_AddDateString(buf, sizeof(buf), &date, (uint8_t*)"dd.mm.yyyy");
      McuHD44780_WriteLineStr(2, (char*)buf);
    }


    hd44780 display with NXP FRDM-KW41Z Board

    hd44780 display with NXP FRDM-KW41Z Board

    Summary

    I’m using HD44780 displays if a simple display solution with no graphics is all that I need. I’m using the McuLib shown here in many projects: it works with many different kinds of microcontrollers and different SDK versions. The driver uses a configuration header file(s) and easily integrates them into Eclipse IDE (MCUXpresso IDE), SDK, and graphical configuration tools (MCUXpresso Configuration Tools).

    Happy Charactering!

    Helpful Links

    Digi-Key’s IoT Component Selector is your one-stop-shop for the IoT

    Topics:
    iot ,tutorial ,mcuxpresso ,microcontroller ,character display ,character ,mcuoneclipse ,mcuxpresso ide

    Published at DZone with permission of

    Opinions expressed by DZone contributors are their own.

    {{ parent.title || parent.header.title}}

    {{ parent.tldr }}

    {{ parent.urlSource.name }}