PIC18 LaurTec Library  3.3.1
Open Source C Library for PIC18 Microcontrollers based on C18 - XC8 Compilers
 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.5
5 Created on Date : 09/03/2012
6 Last update : 15/12/2014
7 
8 CopyRight 2006-2014 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 LCD_44780_I2C_H
64 #define LCD_44780_I2C_H
65 
66 #ifdef __XC8
67  #include <xc.h>
68  #include <stdlib.h>
69 
70  #ifndef _PIC18
71  #error The LCD_44780_I2C Library supports only PIC18 devices
72  #endif
73 #endif
74 
75 #include <delay.h>
76 
77 #include <i2c.h>
78 
79 #ifndef __XC8
80  #include <ctype.h>
81 #endif
82 
83 
84 //**************************************************
85 // LCD constants
86 // Each bit is connected to the PCF8574
87 //**************************************************
88 
89 
90 #define LCD_D0 0b00000001
91 #define LCD_D1 0b00000010
92 #define LCD_D2 0b00000100
93 #define LCD_D3 0b00001000
94 #define LCD_E 0b00010000
95 #define LCD_RW 0b00100000
96 #define LCD_RS 0b01000000
97 #define LCD_LED 0b10000000
98 
99 //**************************************************
100 // PCF8574 Address
101 // PCF8574_ADDRESS_H refers to the embedded address (PCF8574 model)
102 // PCF8574_ADDRESS_L refers to the A0, A1, A2 pins
103 //**************************************************
104 
105 //PCF8574
106 //#define PCF8574_ADDRESS_H 0x40
107 
108 //PCF8574A
109 #define PCF8574_ADDRESS_H 0x70
110 
111 #define PCF8574_ADDRESS_L 0x00
112 
113 //**************************************************
114 // Constant Definitions
115 
116 #define LEFT 0b00000000
117 #define RIGHT 0b00000100
118 #define LCD_LEFT 0b00000000
119 #define LCD_RIGHT 0b00000100
120 
121 #define TURN_ON_CURSOR 0b00000010
122 #define TURN_OFF_CURSOR 0b00000000
123 #define LCD_TURN_ON_CURSOR 0b00000010
124 #define LCD_TURN_OFF_CURSOR 0b00000000
125 
126 #define TURN_ON_LED_LCD 0b00000000
127 #define TURN_OFF_LED_LCD 0b10000000
128 #define LCD_TURN_ON_LED 0b00000000
129 #define LCD_TURN_OFF_LED 0b10000000
130 
131 #define BLINKING_ON 0b00000001
132 #define BLINKING_OFF 0b00000000
133 #define LCD_BLINKING_ON 0b00000001
134 #define LCD_BLINKING_OFF 0b00000000
135 
136 #define BUS_DATA_RATE_LCD 100
137 #define LCD_BUS_DATA_RATE 100
138 
139 //**************************************************
140 
141 
142 
149 void LCD_enable_pulse (void);
150 #define enable_pulse_LCD LCD_enable_pulse
151 #define Epulse enable_pulse_LCD
152 
153 
162 void LCD_send_command (unsigned char data);
163 #define send_command_LCD LCD_send_command
164 #define SendCommand send_command_LCD
165 
166 
171 void LCD_home(void);
172 #define home_LCD LCD_home
173 #define HomeLCD home_LCD
174 
175 
186 void LCD_shift (unsigned char shift, unsigned char number_of_shift);
187 #define shift_LCD LCD_shift
188 #define ShiftLCD shift_LCD
189 
190 
202 void LCD_shift_cursor (unsigned char shift,unsigned char number_of_shift);
203 #define shift_cursor_LCD LCD_shift_cursor
204 #define ShiftCursorLCD shift_cursor_LCD
205 
206 
214 void goto_line_LCD (unsigned char line);
215 #define goto_line_LCD LCD_goto_line
216 #define GotoLineLCD goto_line_LCD
217 
218 
229 void goto_xy_LCD (unsigned char x, unsigned char y);
230 #define goto_xy_LCD LCD_goto_xy
231 
232 
240 void LCD_write_char (unsigned char value);
241 #define write_char_LCD LCD_write_char
242 #define WriteCharLCD write_char_LCD
243 
244 
245 
255 #ifndef __XC8
256 void LCD_write_message (const rom unsigned char *buffer);
257 #endif
258 
259 #ifdef __XC8
260 void LCD_write_message (const unsigned char *buffer);
261 #endif
262 
263 #define write_message_LCD LCD_write_message
264 #define WriteStringLCD write_message_LCD
265 
266 
267 
276 void LCD_write_string (unsigned char *buffer);
277 #define write_string_LCD LCD_write_string
278 #define WriteVarLCD write_string_LCD
279 
280 
294 void LCD_write_integer (int value, unsigned char number_of_digits);
295 #define write_integer_LCD LCD_write_integer
296 #define WriteIntLCD write_integer_LCD
297 
298 
303 void LCD_clear (void);
304 #define clear_LCD LCD_clear
305 #define ClearLCD clear_LCD
306 
307 
319 void LCD_cursor (unsigned char active, unsigned char blinking);
320 #define cursor_LCD LCD_cursor
321 #define CursorLCD cursor_LCD
322 
323 
334 void LCD_backlight (unsigned char active);
335 #define backlight_LCD LCD_backlight
336 #define BacklightLCD backlight_LCD
337 
338 
348 void LCD_initialize (unsigned char quartz_frequency);
349 #define initialize_LCD LCD_initialize
350 #define OpenLCD initialize_LCD
351 
352 
353 #endif