PIC18 LaurTec Library  3.2.0
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.4
5 Created on Date : 09/03/2012
6 Last update : 01/11/2013
7 
8 CopyRight 2006-2013 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 
119 #define TURN_ON_CURSOR 0b00000010
120 #define TURN_OFF_CURSOR 0b00000000
121 
122 #define TURN_ON_LED_LCD 0b00000000
123 #define TURN_OFF_LED_LCD 0b10000000
124 
125 #define BLINKING_ON 0b00000001
126 #define BLINKING_OFF 0b00000000
127 
128 #define BUS_DATA_RATE_LCD 400
129 
130 //**************************************************
131 
132 
133 
140 void enable_pulse_LCD (void);
141 #define Epulse enable_pulse_LCD
142 
143 
152 void send_command_LCD (unsigned char data);
153 #define SendCommand send_command_LCD
154 
155 
160 void home_LCD(void);
161 #define HomeLCD home_LCD
162 
163 
174 void shift_LCD(unsigned char shift, unsigned char number_of_shift);
175 #define ShiftLCD shift_LCD
176 
177 
189 void shift_cursor_LCD(unsigned char shift,unsigned char number_of_shift);
190 #define ShiftCursorLCD shift_cursor_LCD
191 
192 
200 void goto_line_LCD (unsigned char line);
201 #define GotoLineLCD goto_line_LCD
202 
203 
214 void goto_xy_LCD (unsigned char x, unsigned char y);
215 
216 
224 void write_char_LCD (unsigned char value);
225 #define WriteCharLCD write_char_LCD
226 
227 
228 
238 #ifndef __XC8
239 void write_message_LCD(const rom unsigned char *buffer);
240 #endif
241 
242 #ifdef __XC8
243 void write_message_LCD(const unsigned char *buffer);
244 #endif
245 
246 #define WriteStringLCD write_message_LCD
247 
248 
249 
258 void write_string_LCD(unsigned char *buffer);
259 #define WriteVarLCD write_string_LCD
260 
261 
275 void write_integer_LCD(int value, unsigned char number_of_digits);
276 #define WriteIntLCD write_integer_LCD
277 
278 
283 void clear_LCD (void);
284 #define ClearLCD clear_LCD
285 
286 
298 void cursor_LCD(unsigned char active, unsigned char blinking);
299 #define CursorLCD cursor_LCD
300 
301 
312 void backlight_LCD(unsigned char active);
313 #define BacklightLCD backlight_LCD
314 
315 
325 void initialize_LCD(unsigned char quartz_frequency);
326 #define OpenLCD initialize_LCD
327 
328 
329 #endif