YALI
Yet Another LCD Interface
Macros | Functions
unilcd.h File Reference

YALI (Yet Another LCD Interface) library. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LCD_CMD_CLEAR   0x01
 
#define LCD_CMD_HOME   0x02
 
#define LCD_CMD_ENTRY_MODE   0x04
 
#define LCD_CMD_ENTRY_INC_ADDRESS   0x02
 
#define LCD_CMD_ENTRY_SHIFT_LEFT   0x01
 
#define LCD_CMD_DISPLAY   0x08
 
#define LCD_CMD_DISPLAY_ON   0x04
 
#define LCD_CMD_DISPLAY_CUSROR   0x02
 
#define LCD_CMD_DISPLAY_CURSOR_BLINK   0x01
 
#define LCD_CMD_SHIFT   0x10
 
#define LCD_CMD_SHIFT_RIGHT   0x04
 
#define LCD_CMD_SHIFT_DISPLAY   0x08
 
#define LCD_CMD_FUNCTION   0x20
 
#define LCD_CMD_FUNC_8BIT_LENGTH   0x10
 
#define LCD_CMD_FUNC_LINES   0x04
 
#define LCD_CMD_FUNC_FONT   0x08
 
#define LCD_CMD_CG_RAM   0x40
 
#define LCD_CMD_DDRAM   0x80
 
#define INSTRUCTION_MODE_CMD   0x00
 
#define INSTRUCTION_MODE_CHAR   0x01
 
#define sendLCDData(d)   sendLCDInstruction(d, INSTRUCTION_MODE_CHAR)
 This macro send data to the HD44780 controller.
 
#define sendLCDCommand(c)   sendLCDInstruction(c, INSTRUCTION_MODE_CMD)
 This macro send instructions (commands) to the HD44780 controller.
 
#define clearLCD()   sendLCDCommand(LCD_CMD_CLEAR)
 Macro to clear LCD display and reset DDRAM address.
 
#define returnToHome()   sendLCDCommand(LCD_CMD_HOME)
 Macro to move cursor to the home location.
 
#define printChar(c)   sendLCDData(c)
 Macro to print a single character on the LCD.
 
#define printString(s)   printStringLen(s, MAX_STR_LEN)
 Macro to print a null terminate string on the LCD.
 

Functions

VOID initLCDInterface (VOID)
 Initialize LCD interface. More...
 
VOID sendLCDInstruction (UCHAR data, UCHAR mode)
 Send instructions or data to the HD44780 controller. More...
 
VOID initLCD (VOID)
 Initialize HD44780 controller. More...
 
VOID printStringLen (const CHAR *str, UCHAR maxLength)
 Print string on LCD. More...
 
VOID gotoLCDPosition (UCHAR x, UCHAR y)
 Move the cursor to the given coordinates. More...
 
VOID setDisplayState (UCHAR onState)
 Control LCD screen. More...
 
VOID setCursorState (UCHAR cursorState)
 Set cursor display mode. More...
 
VOID setCursorBlinkState (UCHAR blinkState)
 Set cursor blinking mode. More...
 
VOID setCustomChar (UCHAR addr, UCHAR *buffer)
 Load custom character to the LCD RAM. More...
 
VOID setBacklightState (UCHAR backLightState)
 Turn on or off the LCD backlight. More...
 

Detailed Description

YALI (Yet Another LCD Interface) library.

Author
Dilshan R Jayakody (jayak.nosp@m.ody2.nosp@m.000lk.nosp@m.@gma.nosp@m.il.co.nosp@m.m)
Version
1.0
Date
2023-03-23

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ INSTRUCTION_MODE_CHAR

#define INSTRUCTION_MODE_CHAR   0x01

Data (character) mode.

◆ INSTRUCTION_MODE_CMD

#define INSTRUCTION_MODE_CMD   0x00

Command (instruction) mode.

◆ LCD_CMD_CG_RAM

#define LCD_CMD_CG_RAM   0x40

CGRAM (character pattern buffer) command.

◆ LCD_CMD_CLEAR

#define LCD_CMD_CLEAR   0x01

Clears entire display and reset DDRAM address.

◆ LCD_CMD_DDRAM

#define LCD_CMD_DDRAM   0x80

DDRAM (display data buffer) command.

◆ LCD_CMD_DISPLAY

#define LCD_CMD_DISPLAY   0x08

Display and cursor control.

◆ LCD_CMD_DISPLAY_CURSOR_BLINK

#define LCD_CMD_DISPLAY_CURSOR_BLINK   0x01

Enable blinking cursor.

◆ LCD_CMD_DISPLAY_CUSROR

#define LCD_CMD_DISPLAY_CUSROR   0x02

Display cursor as 5×8 block.

◆ LCD_CMD_DISPLAY_ON

#define LCD_CMD_DISPLAY_ON   0x04

Turn on the entire LCD display.

◆ LCD_CMD_ENTRY_INC_ADDRESS

#define LCD_CMD_ENTRY_INC_ADDRESS   0x02

Auto increment the DDRAM address by 1 when a character is written.

◆ LCD_CMD_ENTRY_MODE

#define LCD_CMD_ENTRY_MODE   0x04

Set cursor move direction and specifies display shift.

◆ LCD_CMD_ENTRY_SHIFT_LEFT

#define LCD_CMD_ENTRY_SHIFT_LEFT   0x01

Shift the entire display to the left.

◆ LCD_CMD_FUNC_8BIT_LENGTH

#define LCD_CMD_FUNC_8BIT_LENGTH   0x10

Interface data length is 8-bits. (This mode is not supported by YALI module.)

◆ LCD_CMD_FUNC_FONT

#define LCD_CMD_FUNC_FONT   0x08

Set the character font.

◆ LCD_CMD_FUNC_LINES

#define LCD_CMD_FUNC_LINES   0x04

Number of display lines.

◆ LCD_CMD_FUNCTION

#define LCD_CMD_FUNCTION   0x20

Function mode to set data length, number of display lines and character font.

◆ LCD_CMD_HOME

#define LCD_CMD_HOME   0x02

Return cursor to the home location and shift display to the original position.

◆ LCD_CMD_SHIFT

#define LCD_CMD_SHIFT   0x10

Moves cursor or shifts display.

◆ LCD_CMD_SHIFT_DISPLAY

#define LCD_CMD_SHIFT_DISPLAY   0x08

Shift display.

◆ LCD_CMD_SHIFT_RIGHT

#define LCD_CMD_SHIFT_RIGHT   0x04

Shift display to the right.

Function Documentation

◆ gotoLCDPosition()

VOID gotoLCDPosition ( UCHAR  x,
UCHAR  y 
)

Move the cursor to the given coordinates.

Set the current cursor position to the given row and column.

Parameters
xHorizontal (row) position starting from 0.
yVertical (column) position.
Returns
VOID

◆ initLCD()

VOID initLCD ( VOID  )

Initialize HD44780 controller.

Initialize the LCD controller and clear the screen. This function initializes the LCD controller into the following configuration.

  • Disable the blinking cursor.
  • Hide the cursor from the LCD.
  • Turn on the LCD backlight.
Returns
VOID

◆ initLCDInterface()

VOID initLCDInterface ( VOID  )

Initialize LCD interface.

This function initializes the MCU's I/O pins used by the LCD interface. The I/O pins used in this function are defined in the platform configuration header file (e.g: arduino-conf.h).

Returns
VOID

◆ printStringLen()

VOID printStringLen ( const CHAR str,
UCHAR  maxLength 
)

Print string on LCD.

Print the content of the specified string buffer on the LCD screen. This function print contents starting from the current cursor position.

Parameters
strString buffer.
maxLengthLength of the string buffer.
Returns
VOID

◆ sendLCDInstruction()

VOID sendLCDInstruction ( UCHAR  data,
UCHAR  mode 
)

Send instructions or data to the HD44780 controller.

This function sends instructions or data to the HD44780 controller. The transfer type (such as instructions or data) can select using the mode parameter. This function support all WRITE instructions provided by the HD44780 controller.

Parameters
data8-bit data or instruction code.
modeTransfer mode, such as INSTRUCTION_MODE_CMD or INSTRUCTION_MODE_CHAR.
Returns
VOID

◆ setBacklightState()

VOID setBacklightState ( UCHAR  backLightState)

Turn on or off the LCD backlight.

This function can turn on or off (LED) backlight.

Parameters
backLightStateSet 1 to turn on the LCD backlight. Set 0 to turn off the LCD backlight.
Returns
VOID

◆ setCursorBlinkState()

VOID setCursorBlinkState ( UCHAR  blinkState)

Set cursor blinking mode.

This function can switch the cursor between blinking and static modes.

Parameters
blinkStateSet 1 for blinking, or 0 for the static cursor.
Returns
VOID

◆ setCursorState()

VOID setCursorState ( UCHAR  cursorState)

Set cursor display mode.

This function can turn on or off the cursor.

Parameters
cursorStateSet 1 to turn on the cursor. Set 0 to turn off the cursor.
Returns
VOID

◆ setCustomChar()

VOID setCustomChar ( UCHAR  addr,
UCHAR buffer 
)

Load custom character to the LCD RAM.

Load 5×8 custom character to the specified address of the CGRAM.

Make sure to call the clearLCD function after loading all custom characters. Without this function call, the custom characters will not be displayed on the LCD.

To display the custom characters, call the printChar function with the appropriate address.

Parameters
addrRAM address, ranges from 0 to 7.
buffer8-byte long custom character buffer.
Returns
VOID

◆ setDisplayState()

VOID setDisplayState ( UCHAR  onState)

Control LCD screen.

This function can turn on or off the entire LCD screen. When turn off, the display data remains in the DDRAM of the LCD controller.

Parameters
onStateSet 1 to turn on the LCD display. Set 0 to turn off the LCD display.
Returns
VOID