Project 5  Character Liquid-Crystal Display
Neff Site
Macros | Functions
lcd1602.h File Reference

Header file for the LCD1602 module. More...

Go to the source code of this file.

Macros

#define LCD1602_ADDR   0x27
 
#define LCD1602_ROW_OFFSET   0x40
 
#define LCD1602_DATA   0x01
 
#define LCD1602_COMMAND   0x00
 
#define LCD1602_CLR_E   0x00
 
#define LCD1602_SET_E   0x04
 
#define LCD1602_BACKLIGHT_ON   0x08
 
#define LCD1602_BACKLIGHT_OFF   0x00
 

Functions

void lcd1602_sendCommand (uint8_t cmd)
 Send a command. More...
 
void lcd1602_sendData (uint8_t byte)
 Send a data byte. More...
 
void lcd1602_init (void)
 Initialize the display. More...
 
void lcd1602_displayOn (void)
 Turn the display on. More...
 
void lcd1602_displayOff (void)
 Turn the display off. More...
 
void lcd1602_displayClear (void)
 Clear the display. More...
 
void lcd1602_cursorHome (void)
 Place the cursor at its home position. More...
 
void lcd1602_cursorSet (uint8_t col, uint8_t row)
 Set cursor to the specified position. More...
 
void lcd1602_putchar (const char c)
 Print a character at the display. More...
 
void lcd1602_puts (const char *s)
 Print a string at the display. More...
 

Detailed Description

Header file for the LCD1602 module.

This is a library for the LCD1602 monochrome liquid-crystal display. The module has an i2c interface and uses a 4-bit data transfer mode where the upper 4 bits are the data and the lower 4 bits are control bits. Please see page 33 of the HD44780 data sheet for the details of the data transfer.

I2C Interface
Bit 7 6 5 4 3 2 1 0
I2C D7 D6 D5 D4 D3 D2 D1 D0
HD7780DB7 DB6 DB5 DB4 BL E R/W RS
  • DB7 ... DB4: Data bits for 4-bit operation
  • BL : Background lighting (0: off, 1: on)
  • E : Starts data read/write
  • R/W : Selects read or write (0: write, 1: read)
  • RS : Selects register (0: instruction, 1: data)

Two 4-bit transfers are necessary to send a byte to the display controller. The control bits have to be set appropriately. Look at the following code example for a possible implementation.

uint8_t backlight = LCD1602_BACKLIGHT_OFF;
static void write_4bits(uint8_t data, uint8_t rs)
{
i2c_write(data << 4 | backlight | rs | LCD1602_SET_E);
i2c_write(data << 4 | backlight | rs | LCD1602_CLR_E);
}
static void write_8bits(uint8_t data, uint8_t rs)
{
write_4bits(data >> 4, rs);
write_4bits(data, rs);
}
Author
Wolfgang Neff
Version
2.0
Date
2017-12-20
History
Created: 2013-06-19
Modified: 2016-05-14
Modified: 2017-12-20

Macro Definition Documentation

◆ LCD1602_ADDR

#define LCD1602_ADDR   0x27

◆ LCD1602_BACKLIGHT_OFF

#define LCD1602_BACKLIGHT_OFF   0x00

◆ LCD1602_BACKLIGHT_ON

#define LCD1602_BACKLIGHT_ON   0x08

◆ LCD1602_CLR_E

#define LCD1602_CLR_E   0x00

◆ LCD1602_COMMAND

#define LCD1602_COMMAND   0x00

◆ LCD1602_DATA

#define LCD1602_DATA   0x01

◆ LCD1602_ROW_OFFSET

#define LCD1602_ROW_OFFSET   0x40

◆ LCD1602_SET_E

#define LCD1602_SET_E   0x04

Function Documentation

◆ lcd1602_cursorHome()

void lcd1602_cursorHome ( void  )

Place the cursor at its home position.

◆ lcd1602_cursorSet()

void lcd1602_cursorSet ( uint8_t  col,
uint8_t  row 
)

Set cursor to the specified position.

This routine places the cursor at the specified position. The column and row counting starts with 1.

Parameters
colThe new column position.
rowThe new row position.

◆ lcd1602_displayClear()

void lcd1602_displayClear ( void  )

Clear the display.

Clears the display and sets the cursor to its home position.

◆ lcd1602_displayOff()

void lcd1602_displayOff ( void  )

Turn the display off.

Turns the display and the background lighting off.

◆ lcd1602_displayOn()

void lcd1602_displayOn ( void  )

Turn the display on.

Turns the display and the background lighting on.

◆ lcd1602_init()

void lcd1602_init ( void  )

Initialize the display.

This routine initializes the I2C module and the display controller. Please see page 46 of the HD44780 data sheet for the details.

◆ lcd1602_putchar()

void lcd1602_putchar ( const char  c)

Print a character at the display.

Parameters
cThe character to be printed.

◆ lcd1602_puts()

void lcd1602_puts ( const char *  s)

Print a string at the display.

Parameters
sThe string to be printed.

◆ lcd1602_sendCommand()

void lcd1602_sendCommand ( uint8_t  cmd)

Send a command.

Sends a command to the display controller by an I2C transaction.

Parameters
cmdThe command to be sent.

◆ lcd1602_sendData()

void lcd1602_sendData ( uint8_t  byte)

Send a data byte.

Sends a data byte to the display controller by an I2C transaction.

Parameters
dataThe data byte to be sent.
Contact