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 
117 #ifndef _I2CLCD_H
118 #define _I2CLCD_H
119 
120 //-------------------------------------------------------------------------------------------------------------------
121 
122 //--Display-Configuration-Settings-----------------------------------------------------------------------------------
123 
130 
131 #define LCD_I2C_DEVICE 0x4E
132 #define LCD_LINES 4
133 #define LCD_COLS 20
134 #define LCD_LINE_MODE LCD_2LINE
135 #define LCD_LIGHT_LOW_ACTIVE 0
137 #define LCD_LINE1 0x00
138 #define LCD_LINE2 0x40
139 #define LCD_LINE3 0x14
140 #define LCD_LINE4 0x54
143 
144 #if LCD_LINES > 4
145  #error "#define LCD_LINES must be less or equal to 4"
146 #endif
147 
148 #if LCD_COLS > 20
149  #error "#define LCD_COLS must be less or equal to 20"
150 #endif
151 
152 
153 //-------------------------------------------------------------------------------------------------------------------
154 
155 //--The-following-definitions-are-corresponding-to-the-PIN-Assignment-(see-above)------------------------------------
156 
162 #define LCD_D4_PIN 4
163 #define LCD_D5_PIN 5
164 #define LCD_D6_PIN 6
165 #define LCD_D7_PIN 7
166 #define LCD_RS_PIN 0
167 #define LCD_RW_PIN 1
168 #define LCD_E_PIN 2
169 #define LCD_LIGHT_PIN 3
171 
172 //-------------------------------------------------------------------------------------------------------------------
173 
179 
180 #define LCD_D4 (1 << LCD_D4_PIN)
181 #define LCD_D5 (1 << LCD_D5_PIN)
182 #define LCD_D6 (1 << LCD_D6_PIN)
183 #define LCD_D7 (1 << LCD_D7_PIN)
185 #define LCD_RS (1 << LCD_RS_PIN)
186 #define LCD_RW (1 << LCD_RW_PIN)
187 #define LCD_LIGHT (1 << LCD_LIGHT_PIN)
188 #define LCD_E (1 << LCD_E_PIN)
191 
192 // data & control bits for internal use, do not change!
193 
194 #define CMD_D0 (1 << 0)
195 #define CMD_D1 (1 << 1)
196 #define CMD_D2 (1 << 2)
197 #define CMD_D3 (1 << 3)
198 #define CMD_RS (1 << 4)
199 #define CMD_RW (1 << 5)
204 #define LCD_ADDRESS 0
205 #define LCD_DATA 1
207 
208 //-LCD-COMMANDS------------------------------------------------------------------------------------------------------
220 
223 #define LCD_CLEAR 0x01
224 #define LCD_HOME 0x02
225 #define LCD_DEF_CHAR 0x40
227 
228 
230 #define LCD_ENTRYMODE 0x04
231  #define LCD_INCREASE LCD_ENTRYMODE | 0x02
232  #define LCD_DECREASE LCD_ENTRYMODE | 0x00
233  #define LCD_DISPLAYSHIFTON LCD_ENTRYMODE | 0x01
234  #define LCD_DISPLAYSHIFTOFF LCD_ENTRYMODE | 0x00
236 
237 
239 #define LCD_DISPLAYMODE 0x08
240  #define LCD_DISPLAYON LCD_DISPLAYMODE | 0x04
241  #define LCD_DISPLAYOFF LCD_DISPLAYMODE | 0x00
242  #define LCD_CURSORON LCD_DISPLAYMODE | 0x02
243  #define LCD_CURSOROFF LCD_DISPLAYMODE | 0x00
244  #define LCD_BLINKINGON LCD_DISPLAYMODE | 0x01
245  #define LCD_BLINKINGOFF LCD_DISPLAYMODE | 0x00
247 
248 
250 #define LCD_SHIFTMODE 0x10
251  #define LCD_DISPLAYSHIFT LCD_SHIFTMODE | 0x08
252  #define LCD_CURSORMOVE LCD_SHIFTMODE | 0x00
253  #define LCD_RIGHT LCD_SHIFTMODE | 0x04
254  #define LCD_LEFT LCD_SHIFTMODE | 0x00
256 
257 
259 #define LCD_CONFIGURATION 0x20
260  #define LCD_8BIT LCD_CONFIGURATION | 0x10
261  #define LCD_4BIT LCD_CONFIGURATION | 0x00
262  #define LCD_2LINE LCD_CONFIGURATION | 0x08
263  #define LCD_1LINE LCD_CONFIGURATION | 0x00
264  #define LCD_5X10 LCD_CONFIGURATION | 0x04
265  #define LCD_5X7 LCD_CONFIGURATION | 0x00
267 #define LCD_LIGHT_OFF 0
268 #define LCD_LIGHT_ON LCD_LIGHT
269 
271 //-------------------------------------------------------------------------------------------------------------------
272 
275 //-FUNCTIONS---------------------------------------------------------------------------------------------------------
276 
279 
285 void lcd_write(uint8_t value);
286 
292 uint8_t lcd_read(bool mode);
293 
299 uint8_t lcd_getbyte(bool mode);
300 
301 //-------------------------------------------------------------------------------------------------------------------
305 //-FUNCTIONS---------------------------------------------------------------------------------------------------------
306 
309 
314 void lcd_init(void);
315 
321 void lcd_command(uint8_t command);
322 
323 
331 bool lcd_gotolc(uint8_t line, uint8_t col);
332 
338 void lcd_putchar(char value);
339 
348 bool lcd_putcharlc(uint8_t line, uint8_t col, char value);
349 
355 void lcd_print(char *string);
356 
362 void lcd_print_P(PGM_P string);
363 
372 bool lcd_printlc(uint8_t line, uint8_t col, char *string);
373 
382 bool lcd_printlc_P(uint8_t line, uint8_t col, PGM_P string);
383 
392 bool lcd_printlcc(uint8_t line, uint8_t col, char *string);
393 
402 bool lcd_printlcc_P(uint8_t line, uint8_t col, PGM_P string);
403 
409 bool lcd_nextline(void);
410 
418 bool lcd_getlc(uint8_t *line, uint8_t*col);
419 
425 bool lcd_busy(void);
426 
433 void lcd_light(bool light);
434 
441 void lcd_def_char(PGM_P chardata, uint8_t number);
442 
443 //-------------------------------------------------------------------------------------------------------------------
446 #endif
void lcd_light(bool light)
Turn backlight ON/OFF.
Definition: i2clcd.c:333
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:190
uint8_t lcd_read(bool mode)
Read data from display over i2c (for internal use)
Definition: i2clcd.c:98
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:226
bool lcd_printlc_P(uint8_t line, uint8_t col, PGM_P string)
Print string from Flash to position (If string is longer than LCD_COLS overwrite first chars in line)...
Definition: i2clcd.c:208
bool lcd_putcharlc(uint8_t line, uint8_t col, char value)
Put char to position.
Definition: i2clcd.c:180
void lcd_command(uint8_t command)
Issue a command to the display.
Definition: i2clcd.c:145
bool lcd_busy(void)
Check if LCD is busy.
Definition: i2clcd.c:353
void lcd_putchar(char value)
Put char to cursor position.
Definition: i2clcd.c:172
uint8_t lcd_getbyte(bool mode)
Read one byte over i2c from display.
Definition: i2clcd.c:135
void lcd_print_P(PGM_P string)
Print string from Flash to cursor position.
Definition: i2clcd.c:162
void lcd_print(char *string)
Print string to cursor position.
Definition: i2clcd.c:153
bool lcd_getlc(uint8_t *line, uint8_t *col)
Get line and col of the cursor position.
Definition: i2clcd.c:304
void lcd_write(uint8_t value)
Write nibble to display with toggle of enable-bit.
Definition: i2clcd.c:76
bool lcd_nextline(void)
Go to nextline (if next line > LCD_LINES return false)
Definition: i2clcd.c:291
void lcd_def_char(PGM_P chardata, uint8_t number)
Define a user character.
Definition: i2clcd.c:366
void lcd_init(void)
Display initialization sequence.
Definition: i2clcd.c:49
bool lcd_printlcc_P(uint8_t line, uint8_t col, PGM_P string)
Print string from flash to position (If string is longer than LCD_COLS continue in next line) ...
Definition: i2clcd.c:248
bool lcd_gotolc(uint8_t line, uint8_t col)
Go to position.
Definition: i2clcd.c:270