LTlib LaurTec Library  4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
LCD_44780_I2C.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.6
5 Created on Date : 09/03/2012
6 Last update : 05/06/2016
7 
8 CopyRight 2006-2015 all rights are reserved
9 
10 ********************************************************
11 SOFTWARE LICENSE AGREEMENT
12 ********************************************************
13 
14 The usage of the supplied software imply the acceptance of the following license.
15 
16 The software supplied herewith by Mauro Laurenti (the Author) is intended for
17 use solely and exclusively on Microchip PIC Microcontroller (registered mark).
18 The software is owned by the Author, and is protected under applicable
19 copyright laws. All rights are reserved.
20 Any use in violation of the foregoing restrictions may subject the
21 user to criminal sanctions under applicable laws, as well as to civil liability
22 for the breach of the terms and conditions of this license.
23 Commercial use is forbidden without a written acknowledgement with the Author.
24 Personal or educational use is allowed if the application containing the
25 following software doesn't aim to commercial use or monetary earning of any kind.
26 
27 THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
28 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
31 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33 
34 ********************************************************
35 PURPOSES
36 ********************************************************
37 
38 
39  This library contains all the functions that are handy for controlling
40  an LCD with a 44780 Hitachi controller via an I2C interface made with a PCF8574
41 
42 Before using the functions you have to properly initialize the I2C module to 100KHz.
43 hardware connections are (using Eagle CAD nomenclature):
44 
45 PCF8574 P0 -> LCD D4
46 PCF8574 P1 -> LCD D5
47 PCF8574 P2 -> LCD D6
48 PCF8574 P3 -> LCD D7
49 PCF8574 P4 -> LCD E
50 PCF8574 P5 -> LCD R/W
51 PCF8574 P6 -> LCD RS
52 PCF8574 P7 -> LCD LED (use a PNP transistor as buffer to drive the backlight LED).
53 
54 SDA, SCL must be connected to the I2C buffer with pull-up resistors.
55 A0-A1-A2 address pins must be set as required.
56 Set PCF8574_ADDRESS_L (see below) accordingly to the address pis A0-A1-A2.
57 
58 More details and pictures can be downloaded from the Brief Note BN0015 (www.LaurTec.com)
59 
60 **********************************************************************************************/
61 
62 
63 #ifndef LTLIB_LCD_44780_I2C_H
64 #define LTLIB_LCD_44780_I2C_H
65 
66 #ifdef __XC8
67  #include <xc.h>
68  #include <stdlib.h>
69 #endif
70 
71 #ifndef __XC8
72  #include <ctype.h>
73 #endif
74 
75 //*****************************************
76 // Library Test
77 //*****************************************
78 
79 #include "LTlib.h"
80 
81 #ifndef LTLIB_DELAY_H
82  #error The LCD_44780_I2C Library requires the "delay" library to be included.
83 #endif
84 
85 #if defined (LTLIB_MCP2300X_H) || defined (LTLIB_PCF8574_H)
86 
87 #else
88  #error The LCD_44780_I2C Library requires the "MCP2300x" or "PCF8574" library to be included.
89 #endif
90 
91 
92 //**************************************************
93 // PCF8574 Address
94 // PCF8574_ADDRESS_H refers to the embedded address (PCF8574 model)
95 // PCF8574_ADDRESS_L refers to the A0, A1, A2 pins
96 //**************************************************
97 
98 //#define PCF8574
99 //#define PCF8574A
100 //#define MCP23008
101 
102 #if defined (PCF8574) || defined (PCF8574A) || defined (MCP23008)
103 
104 #else
105  #define MCP23008
106 #endif
107 
108 //**************************************************
109 // Device Address
110 //
111 //**************************************************
112 
113 //PCF8574
114 #ifdef PCF8574
115  #define DEVICE_ADDRESS_H 0x40
116  #define DEVICE_ADDRESS_L 0x00
117  #define PCF8574_GENERIC
118 #endif
119 
120 //PCF8574A
121 #ifdef PCF8574A
122  #define DEVICE_ADDRESS_H 0x70
123  #define DEVICE_ADDRESS_L 0x00
124  #define PCF8574_GENERIC
125 #endif
126 
127 #ifdef MCP23008
128  // DEVICE_ADDRESS_H is not needed since the MCP23008 library has it already
129  // so it is just set to 0x00 (not to 0x04)
130  #define DEVICE_ADDRESS_H 0x00
131  #define DEVICE_ADDRESS_L 0x00
132 #endif
133 
134 //**************************************************
135 // LCD constants
136 // Each bit is connected to the PCF8574/MC23008
137 //**************************************************
138 
139 // Standard LaurTec Definition
140 #define LCD_D0 0b00000001
141 #define LCD_D1 0b00000010
142 #define LCD_D2 0b00000100
143 #define LCD_D3 0b00001000
144 #define LCD_E 0b00010000
145 #define LCD_RW 0b00100000
146 #define LCD_RS 0b01000000
147 #define LCD_LED 0b10000000
148 
149 //PCF8574 LCD module adapter layout (may differ from product to product)
150 //#define LCD_D0 0b00010000
151 //#define LCD_D1 0b00100000
152 //#define LCD_D2 0b01000000
153 //#define LCD_D3 0b10000000
154 //#define LCD_E 0b00000100
155 //#define LCD_RW 0b00000010
156 //#define LCD_RS 0b00000001
157 //#define LCD_LED 0b00001000
158 
159 //*********************************************************
160 // LCD Back Light driver
161 //*********************************************************
162 
163 #define LCD_DRIVER_NPN
164 //#define LCD_DRIVER_PNP
165 
166 //*********************************************************
167 // Depending on the chip a different baud rate is set
168 //*********************************************************
169 #define BUS_DATA_RATE_LCD 100
170 #define LCD_BUS_DATA_RATE 100
171 
172 #ifdef MCP23008
173 
174  #undef BUS_DATA_RATE_LCD
175  #undef LCD_BUS_DATA_RATE
176 
177  #define BUS_DATA_RATE_LCD 100
178  #define LCD_BUS_DATA_RATE 100
179 #endif
180 
181 
182 //**************************************************
183 // Constant Definitions
184 //**************************************************
185 
186 #define LEFT 0b00000000
187 #define RIGHT 0b00000100
188 #define LCD_LEFT 0b00000000
189 #define LCD_RIGHT 0b00000100
190 
191 #define TURN_ON_CURSOR 0b00000010
192 #define TURN_OFF_CURSOR 0b00000000
193 #define LCD_TURN_ON_CURSOR 0b00000010
194 #define LCD_TURN_OFF_CURSOR 0b00000000
195 
196 #define BLINKING_ON 0b00000001
197 #define BLINKING_OFF 0b00000000
198 #define LCD_BLINKING_ON 0b00000001
199 #define LCD_BLINKING_OFF 0b00000000
200 
201 #define ZERO_CLEANING_ON 0x01
202 #define ZERO_CLEANING_OFF 0x00
203 #define LCD_ZERO_CLEANING_ON 0x01
204 #define LCD_ZERO_CLEANING_OFF 0x00
205 
206 //*********************************************************
207 // Depending on the chip a different ON-OFF state is used
208 //*********************************************************
209 
210 #ifdef LCD_DRIVER_NPN
211  #define TURN_ON_LED_LCD LCD_LED
212  #define TURN_OFF_LED_LCD 0b00000000
213  #define LCD_TURN_ON_LED LCD_LED
214  #define LCD_TURN_OFF_LED 0b00000000
215 #endif
216 
217 #ifdef LCD_DRIVER_PNP
218  #define TURN_ON_LED_LCD 0b00000000
219  #define TURN_OFF_LED_LCD LCD_LED
220  #define LCD_TURN_ON_LED 0b00000000
221  #define LCD_TURN_OFF_LED LCD_LED
222 #endif
223 
224 //**************************************************
225 
226 
227 
234 void LCD_enable_pulse (void);
235 #define enable_pulse_LCD LCD_enable_pulse
236 
237 
246 void LCD_send_command (unsigned char data);
247 #define send_command_LCD LCD_send_command
248 
249 
254 void LCD_home(void);
255 #define home_LCD LCD_home
256 
257 
268 void LCD_shift (unsigned char shift, unsigned char number_of_shift);
269 #define shift_LCD LCD_shift
270 
271 
283 void LCD_shift_cursor (unsigned char shift,unsigned char number_of_shift);
284 #define shift_cursor_LCD LCD_shift_cursor
285 
286 
294 void goto_line_LCD (unsigned char line);
295 #define goto_line_LCD LCD_goto_line
296 
297 
308 void goto_xy_LCD (unsigned char x, unsigned char y);
309 #define goto_xy_LCD LCD_goto_xy
310 
311 
319 void LCD_write_char (unsigned char value);
320 #define write_char_LCD LCD_write_char
321 
322 
332 #ifndef __XC8
333 void LCD_write_message (const rom unsigned char *buffer);
334 #endif
335 
336 #ifdef __XC8
337 void LCD_write_message (const unsigned char *buffer);
338 #endif
339 
340 #define write_message_LCD LCD_write_message
341 
342 
351 void LCD_write_string (unsigned char *buffer);
352 #define write_string_LCD LCD_write_string
353 
354 
370 void LCD_write_integer(int value, unsigned char number_of_digits, unsigned char zero_cleaning);
371 #define write_integer_LCD LCD_write_integer
372 
373 
378 void LCD_clear (void);
379 #define clear_LCD LCD_clear
380 
381 
393 void LCD_cursor (unsigned char active, unsigned char blinking);
394 #define cursor_LCD LCD_cursor
395 
396 
407 void LCD_backlight (unsigned char active);
408 #define backlight_LCD LCD_backlight
409 
410 
420 void LCD_initialize (unsigned char quartz_frequency);
421 #define initialize_LCD LCD_initialize
422 
423 
424 #endif