I2CLCD
HD4470 LCD driver via I2C interface
 All Functions Groups Pages
D:/Projekte/AVR/i2clcd/i2clcd.h
1 /*****************************************************************************
2 
3  i2clcd.h - LCD over I2C library
4  Designed for HD44870 based LCDs with I2C expander PCF8574X
5  on Atmels AVR MCUs
6 
7  Copyright (C) 2006 Nico Eichelmann and Thomas Eichelmann
8  2014 clean up by Falk Brunner
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 
24  You can contact the authors at info@computerheld.de
25 
26 *****************************************************************************/
27 
116 #ifndef _I2CLCD_H
117 #define _I2CLCD_H
118 
119 //-------------------------------------------------------------------------------------------------------------------
120 
121 //--Display-Configuration-Settings-----------------------------------------------------------------------------------
122 
129 #define LCD_I2C_DEVICE 0x4E
130 #define LCD_LINES 2
131 #define LCD_COLS 16
132 #define LCD_LINE_MODE LCD_2LINE
134 #define LCD_LINE1 0x00
135 #define LCD_LINE2 0x40
136 #define LCD_LINE3 0x40
137 #define LCD_LINE4 0x60
139 
140 #if LCD_LINES > 4
141  #error "#define LCD_LINES must be less or equal to 4"
142 #endif
143 
144 #if LCD_COLS > 20
145  #error "#define LCD_COLS must be less or equal to 20"
146 #endif
147 
148 
149 //-------------------------------------------------------------------------------------------------------------------
150 
151 //--The-following-definitions-are-corresponding-to-the-PIN-Assignment-(see-above)------------------------------------
152 
158 #define LCD_D4_PIN 4
159 #define LCD_D5_PIN 5
160 #define LCD_D6_PIN 6
161 #define LCD_D7_PIN 7
162 #define LCD_RS_PIN 0
163 #define LCD_RW_PIN 1
164 #define LCD_E_PIN 2
165 #define LCD_LIGHT_PIN 3
167 
168 //-------------------------------------------------------------------------------------------------------------------
169 
175 
176 #define LCD_D4 (1 << LCD_D4_PIN)
177 #define LCD_D5 (1 << LCD_D5_PIN)
178 #define LCD_D6 (1 << LCD_D6_PIN)
179 #define LCD_D7 (1 << LCD_D7_PIN)
181 #define LCD_RS (1 << LCD_RS_PIN)
182 #define LCD_RW (1 << LCD_RW_PIN)
183 #define LCD_LIGHT_N (1 << LCD_LIGHT_PIN)
184 #define LCD_E (1 << LCD_E_PIN)
187 
188 // data & control bits for internal use, do not change!
189 
190 #define CMD_D0 (1 << 0)
191 #define CMD_D1 (1 << 1)
192 #define CMD_D2 (1 << 2)
193 #define CMD_D3 (1 << 3)
194 #define CMD_RS (1 << 4)
195 #define CMD_RW (1 << 5)
200 #define LCD_ADDRESS 0
201 #define LCD_DATA 1
203 
204 //-LCD-COMMANDS------------------------------------------------------------------------------------------------------
216 
219 #define LCD_CLEAR 0x01
220 #define LCD_HOME 0x02
222 
223 
225 #define LCD_ENTRYMODE 0x04
226  #define LCD_INCREASE LCD_ENTRYMODE | 0x02
227  #define LCD_DECREASE LCD_ENTRYMODE | 0x00
228  #define LCD_DISPLAYSHIFTON LCD_ENTRYMODE | 0x01
229  #define LCD_DISPLAYSHIFTOFF LCD_ENTRYMODE | 0x00
231 
232 
234 #define LCD_DISPLAYMODE 0x08
235  #define LCD_DISPLAYON LCD_DISPLAYMODE | 0x04
236  #define LCD_DISPLAYOFF LCD_DISPLAYMODE | 0x00
237  #define LCD_CURSORON LCD_DISPLAYMODE | 0x02
238  #define LCD_CURSOROFF LCD_DISPLAYMODE | 0x00
239  #define LCD_BLINKINGON LCD_DISPLAYMODE | 0x01
240  #define LCD_BLINKINGOFF LCD_DISPLAYMODE | 0x00
242 
243 
245 #define LCD_SHIFTMODE 0x10
246  #define LCD_DISPLAYSHIFT LCD_SHIFTMODE | 0x08
247  #define LCD_CURSORMOVE LCD_SHIFTMODE | 0x00
248  #define LCD_RIGHT LCD_SHIFTMODE | 0x04
249  #define LCD_LEFT LCD_SHIFTMODE | 0x00
251 
252 
254 #define LCD_CONFIGURATION 0x20
255  #define LCD_8BIT LCD_CONFIGURATION | 0x10
256  #define LCD_4BIT LCD_CONFIGURATION | 0x00
257  #define LCD_4LINE 0x09
258  #define LCD_2LINE LCD_CONFIGURATION | 0x08
259  #define LCD_1LINE LCD_CONFIGURATION | 0x00
260  #define LCD_5X10 LCD_CONFIGURATION | 0x04
261  #define LCD_5X7 LCD_CONFIGURATION | 0x00
263 #define LCD_LIGHT_OFF LCD_LIGHT_N // low active
264 #define LCD_LIGHT_ON 0x00
265 
267 //-------------------------------------------------------------------------------------------------------------------
268 
271 //-FUNCTIONS---------------------------------------------------------------------------------------------------------
272 
275 
281 void lcd_write_i2c(uint8_t value);
282 
288 void lcd_write(uint8_t value);
289 
294 uint8_t lcd_read_i2c(void);
295 
301 uint8_t lcd_read(bool mode);
302 
308 uint8_t lcd_getbyte(bool mode);
309 
310 //-------------------------------------------------------------------------------------------------------------------
314 //-FUNCTIONS---------------------------------------------------------------------------------------------------------
315 
318 
323 void lcd_init(void);
324 
330 void lcd_command(uint8_t command);
331 
332 
340 bool lcd_gotolc(uint8_t line, uint8_t col);
341 
347 void lcd_putchar(char value);
348 
357 bool lcd_putcharlr(uint8_t line, uint8_t col, char value);
358 
364 void lcd_print(char *string);
365 
371 void lcd_print_P(PGM_P string);
372 
381 bool lcd_printlc(uint8_t line, uint8_t col, char *string);
382 
391 bool lcd_printlc_P(uint8_t line, uint8_t col, char *string);
392 
401 bool lcd_printlcc(uint8_t line, uint8_t col, char *string);
402 
411 bool lcd_printlcc_P(uint8_t line, uint8_t col, char *string);
412 
418 bool lcd_nextline(void);
419 
427 bool lcd_getlc(uint8_t *line, uint8_t*col);
428 
434 bool lcd_busy(void);
435 
442 void lcd_light(bool light);
443 
444 //-------------------------------------------------------------------------------------------------------------------
447 #endif
void lcd_light(bool light)
Turn backlight ON/OFF.
Definition: i2clcd.c:336
bool lcd_printlc(uint8_t line, uint8_t col, char *string)
Print string to position (If string is longer than LCD_COLS overwrite first chars in line) ...
Definition: i2clcd.c:193
uint8_t lcd_read(bool mode)
Read data from display over i2c (for internal use)
Definition: i2clcd.c:109
bool lcd_printlcc(uint8_t line, uint8_t col, char *string)
Print string to position (If string is longer than LCD_COLS continue in next line) ...
Definition: i2clcd.c:229
void lcd_write_i2c(uint8_t value)
Write data to i2c (for internal use)
Definition: i2clcd.c:71
bool lcd_printlc_P(uint8_t line, uint8_t col, char *string)
Print string from Flash to position (If string is longer than LCD_COLS overwrite first chars in line)...
Definition: i2clcd.c:211
uint8_t lcd_read_i2c(void)
Read data from i2c (for internal use)
Definition: i2clcd.c:98
void lcd_command(uint8_t command)
Issue a command to the display.
Definition: i2clcd.c:148
bool lcd_busy(void)
Check if LCD is busy.
Definition: i2clcd.c:349
void lcd_putchar(char value)
Put char to cursor position.
Definition: i2clcd.c:175
bool lcd_putcharlr(uint8_t line, uint8_t col, char value)
Put char to position.
uint8_t lcd_getbyte(bool mode)
Read one byte over i2c from display.
Definition: i2clcd.c:138
void lcd_print_P(PGM_P string)
Print string from Flash to cursor position.
Definition: i2clcd.c:165
void lcd_print(char *string)
Print string to cursor position.
Definition: i2clcd.c:156
bool lcd_getlc(uint8_t *line, uint8_t *col)
Get line and col of the cursor position.
Definition: i2clcd.c:307
void lcd_write(uint8_t value)
Write nibble to display with toggle of enable-bit.
Definition: i2clcd.c:80
bool lcd_nextline(void)
Go to nextline (if next line > LCD_LINES return false)
Definition: i2clcd.c:294
void lcd_init(void)
Display initialization sequence.
Definition: i2clcd.c:49
bool lcd_printlcc_P(uint8_t line, uint8_t col, char *string)
Print string from flash to position (If string is longer than LCD_COLS continue in next line) ...
Definition: i2clcd.c:251
bool lcd_gotolc(uint8_t line, uint8_t col)
Go to position.
Definition: i2clcd.c:273