DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

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.

Erich Styger user avatar by
Erich Styger
·
Jan. 29, 19 · Tutorial
Like (2)
Save
Tweet
Share
8.29K Views

Join the DZone community and get the full member experience.

Join For Free

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 b2200 with integrated MCUXpresso Configuration Toolsmcuxpresso ide 10.3.0

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

    • Example project used in this article
    • HD44780 2×16 Character Display for Kinetis and Freedom Board
    • Character LCD with 4 Lines and up to 64 Characters per Line
    • Character LCD with 4 Lines
    • MCU library
    • MCUXpresso IDE
    • MCUXpresso SDK
    • FRDM-KW41Z board
    Software development kit Driver (software)

    Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

    Opinions expressed by DZone contributors are their own.

    Popular on DZone

    • ChatGPT: The Unexpected API Test Automation Help
    • Secrets Management
    • Express Hibernate Queries as Type-Safe Java Streams
    • How To Validate Three Common Document Types in Python

    Comments

    Partner Resources

    X

    ABOUT US

    • About DZone
    • Send feedback
    • Careers
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 600 Park Offices Drive
    • Suite 300
    • Durham, NC 27709
    • support@dzone.com
    • +1 (919) 678-0300

    Let's be friends: