I2CLCD
HD4470 LCD driver via I2C interface
 All Functions Groups Pages
/*****************************************************************************
i2clcd.h - LCD over I2C library
Designed for HD44870 based LCDs with I2C expander PCF8574X
on Atmels AVR MCUs
Copyright (C) 2006 Nico Eichelmann and Thomas Eichelmann
2014 clean up by Falk Brunner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
You can contact the authors at info@computerheld.de
*****************************************************************************/
#ifndef _I2CLCD_H
#define _I2CLCD_H
//-------------------------------------------------------------------------------------------------------------------
//--Display-Configuration-Settings-----------------------------------------------------------------------------------
#define LCD_I2C_DEVICE 0x4E
#define LCD_LINES 4
#define LCD_COLS 20
#define LCD_LINE_MODE LCD_2LINE
#define LCD_LIGHT_LOW_ACTIVE 0
#define LCD_LINE1 0x00
#define LCD_LINE2 0x40
#define LCD_LINE3 0x14
#define LCD_LINE4 0x54
#if LCD_LINES > 4
#error "#define LCD_LINES must be less or equal to 4"
#endif
#if LCD_COLS > 20
#error "#define LCD_COLS must be less or equal to 20"
#endif
//-------------------------------------------------------------------------------------------------------------------
//--The-following-definitions-are-corresponding-to-the-PIN-Assignment-(see-above)------------------------------------
#define LCD_D4_PIN 4
#define LCD_D5_PIN 5
#define LCD_D6_PIN 6
#define LCD_D7_PIN 7
#define LCD_RS_PIN 0
#define LCD_RW_PIN 1
#define LCD_E_PIN 2
#define LCD_LIGHT_PIN 3
//-------------------------------------------------------------------------------------------------------------------
#define LCD_D4 (1 << LCD_D4_PIN)
#define LCD_D5 (1 << LCD_D5_PIN)
#define LCD_D6 (1 << LCD_D6_PIN)
#define LCD_D7 (1 << LCD_D7_PIN)
#define LCD_RS (1 << LCD_RS_PIN)
#define LCD_RW (1 << LCD_RW_PIN)
#define LCD_LIGHT (1 << LCD_LIGHT_PIN)
#define LCD_E (1 << LCD_E_PIN)
// data & control bits for internal use, do not change!
#define CMD_D0 (1 << 0)
#define CMD_D1 (1 << 1)
#define CMD_D2 (1 << 2)
#define CMD_D3 (1 << 3)
#define CMD_RS (1 << 4)
#define CMD_RW (1 << 5)
#define LCD_ADDRESS 0
#define LCD_DATA 1
//-LCD-COMMANDS------------------------------------------------------------------------------------------------------
#define LCD_CLEAR 0x01
#define LCD_HOME 0x02
#define LCD_DEF_CHAR 0x40
#define LCD_ENTRYMODE 0x04
#define LCD_INCREASE LCD_ENTRYMODE | 0x02
#define LCD_DECREASE LCD_ENTRYMODE | 0x00
#define LCD_DISPLAYSHIFTON LCD_ENTRYMODE | 0x01
#define LCD_DISPLAYSHIFTOFF LCD_ENTRYMODE | 0x00
#define LCD_DISPLAYMODE 0x08
#define LCD_DISPLAYON LCD_DISPLAYMODE | 0x04
#define LCD_DISPLAYOFF LCD_DISPLAYMODE | 0x00
#define LCD_CURSORON LCD_DISPLAYMODE | 0x02
#define LCD_CURSOROFF LCD_DISPLAYMODE | 0x00
#define LCD_BLINKINGON LCD_DISPLAYMODE | 0x01
#define LCD_BLINKINGOFF LCD_DISPLAYMODE | 0x00
#define LCD_SHIFTMODE 0x10
#define LCD_DISPLAYSHIFT LCD_SHIFTMODE | 0x08
#define LCD_CURSORMOVE LCD_SHIFTMODE | 0x00
#define LCD_RIGHT LCD_SHIFTMODE | 0x04
#define LCD_LEFT LCD_SHIFTMODE | 0x00
#define LCD_CONFIGURATION 0x20
#define LCD_8BIT LCD_CONFIGURATION | 0x10
#define LCD_4BIT LCD_CONFIGURATION | 0x00
#define LCD_2LINE LCD_CONFIGURATION | 0x08
#define LCD_1LINE LCD_CONFIGURATION | 0x00
#define LCD_5X10 LCD_CONFIGURATION | 0x04
#define LCD_5X7 LCD_CONFIGURATION | 0x00
#define LCD_LIGHT_OFF 0
#define LCD_LIGHT_ON LCD_LIGHT
//-------------------------------------------------------------------------------------------------------------------
//-FUNCTIONS---------------------------------------------------------------------------------------------------------
void lcd_write(uint8_t value);
uint8_t lcd_read(bool mode);
uint8_t lcd_getbyte(bool mode);
//-------------------------------------------------------------------------------------------------------------------
//-FUNCTIONS---------------------------------------------------------------------------------------------------------
void lcd_init(void);
void lcd_command(uint8_t command);
bool lcd_gotolc(uint8_t line, uint8_t col);
void lcd_putchar(char value);
bool lcd_putcharlc(uint8_t line, uint8_t col, char value);
void lcd_print(char *string);
void lcd_print_P(PGM_P string);
bool lcd_printlc(uint8_t line, uint8_t col, char *string);
bool lcd_printlc_P(uint8_t line, uint8_t col, PGM_P string);
bool lcd_printlcc(uint8_t line, uint8_t col, char *string);
bool lcd_printlcc_P(uint8_t line, uint8_t col, PGM_P string);
bool lcd_nextline(void);
bool lcd_getlc(uint8_t *line, uint8_t*col);
bool lcd_busy(void);
void lcd_light(bool light);
void lcd_def_char(PGM_P chardata, uint8_t number);
//-------------------------------------------------------------------------------------------------------------------
#endif