import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js"; const __pageData = JSON.parse('{"title":"HD44780 LCD Driver","description":"","frontmatter":{},"headers":[],"relativePath":"features/hd44780.md","filePath":"features/hd44780.md","lastUpdated":null}'); const _sfc_main = { name: "features/hd44780.md" }; const _hoisted_1 = /* @__PURE__ */ createStaticVNode('

HD44780 LCD Driver

Supported Hardware

LCD modules using HD44780U IC or equivalent, communicating in 4-bit mode.

ModuleSizeNotes
1602A16x2, 5x8 dots
2004A20x4, 5x8 dotsUntested, not currently supported

To run these modules at 3.3V, an additional MAX660 voltage converter IC must be soldered on, along with two 10µF capacitors. See this page for more details.

Usage

Add the following to your rules.mk:

make
HD44780_ENABLE = yes

Basic Configuration

Add the following to your config.h:

DefineDefaultDescription
HD44780_DATA_PINSNot defined(Required) An array of four GPIO pins connected to the display's D4-D7 pins, eg. { B1, B3, B2, B6 }
HD44780_RS_PINNot defined(Required) The GPIO connected to the display's RS pin
HD44780_RW_PINNot defined(Required) The GPIO connected to the display's RW pin
HD44780_E_PINNot defined(Required) The GPIO connected to the display's E pin
HD44780_DISPLAY_COLS16The number of visible characters on a single line of the display
HD44780_DISPLAY_LINES2The number of visible lines on the display
HD44780_WRAP_LINESNot definedIf defined, input characters will wrap to the next line

Examples

Hello World

Add the following to your keymap.c:

c
void keyboard_post_init_user(void) {\n    hd44780_init(true, true); // Show blinking cursor\n    hd44780_puts_P(PSTR("Hello, world!\\n"));\n}

Custom Character Definition

Up to eight custom characters can be defined. This data is stored in the Character Generator RAM (CGRAM), and is not persistent across power cycles.

This example defines the QMK Psi as the first custom character. The first 16 positions in the character set are reserved for the eight custom characters duplicated.

Byte |      16 8 4 2 1\n   1 | x x x ■ □ ■ □ ■\n   2 | x x x ■ □ ■ □ ■\n   3 | x x x ■ □ ■ □ ■\n   4 | x x x □ ■ ■ ■ □\n   5 | x x x □ □ ■ □ □\n   6 | x x x □ □ ■ □ □\n   7 | x x x □ □ ■ □ □\n   8 | x x x □ □ □ □ □
c
const uint8_t PROGMEM psi[8] = { 0x15, 0x15, 0x15, 0x0E, 0x04, 0x04, 0x04, 0x00 };\n\nvoid keyboard_post_init_user(void) {\n    hd44780_init(false, false);\n    hd44780_define_char_P(0, psi);\n    // Cursor is incremented while defining characters so must be reset\n    hd44780_home();\n    // 0x08 to avoid null terminator\n    hd44780_puts_P(PSTR("\\x08 QMK Firmware"));\n}

API

void hd44780_init(bool cursor, bool blink)

Initialize the display.

This function should be called only once, before any of the other functions can be called.

Arguments


void hd44780_clear(void)

Clear the display.

This function is called on init.


void hd44780_home(void)

Move the cursor to the home position.

This function is called on init.


void hd44780_on(bool cursor, bool blink)

Turn the display on, and/or set the cursor properties.

This function is called on init.

Arguments


void hd44780_off(void)

Turn the display off.


void hd44780_set_cursor(uint8_t col, uint8_t line)

Move the cursor to the specified position on the display.

Arguments


void hd44780_putc(char c)

Print a character to the display. The newline character \\n will move the cursor to the start of the next line.

The exact character shown may depend on the ROM code of your particular display - refer to the datasheet for the full character set.

Arguments


void hd44780_puts(const char *s)

Print a string of characters to the display.

Arguments


void hd44780_puts_P(const char *s)

Print a string of characters from PROGMEM to the display.

On ARM devices, this function is simply an alias of hd44780_puts().

Arguments


void hd44780_define_char(uint8_t index, uint8_t *data)

Define a custom character.

Arguments


void hd44780_define_char_P(uint8_t index, const uint8_t *data)

Define a custom character from PROGMEM.

On ARM devices, this function is simply an alias of hd44780_define_char().

Arguments


bool hd44780_busy(void)

Indicates whether the display is currently processing, and cannot accept instructions.

Return Value

true if the display is busy.


void hd44780_write(uint8_t data, bool isData)

Write a byte to the display.

Arguments


uint8_t hd44780_read(bool isData)

Read a byte from the display.

Arguments

Return Value

If isData is true, the returned byte will be the character at the current DDRAM address. Otherwise, it will be the current DDRAM address and the busy flag.


void hd44780_command(uint8_t command)

Send a command to the display. Refer to the datasheet and hd44780.h for the valid commands and defines.

This function waits for the display to clear the busy flag before sending the command.

Arguments


void hd44780_data(uint8_t data)

Send a byte of data to the display.

This function waits for the display to clear the busy flag before sending the data.

Arguments


void hd44780_set_cgram_address(uint8_t address)

Set the CGRAM address.

This function is used when defining custom characters.

Arguments


void hd44780_set_ddram_address(uint8_t address)

Set the DDRAM address.

This function is used when printing characters to the display, and setting the cursor.

Arguments

', 117); const _hoisted_118 = [ _hoisted_1 ]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("div", null, _hoisted_118); } const hd44780 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { __pageData, hd44780 as default };