PIC18 LaurTec Library  3.1.2
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 acknowledgment 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 connetions 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 adderss pins must be set as required.
56 Set PCF8574_ADDRESS_L (see below) accordengly 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 #ifdef __18CXX
78  #include <i2c.h>
79 #endif
80 
81 #ifndef __XC8
82  #include <ctype.h>
83 #endif
84 
85 
86 //**************************************************
87 // LCD constants
88 // Each bit is connected to the PCF8574
89 //**************************************************
90 
91 
92 #define LCD_D0 0b00000001
93 #define LCD_D1 0b00000010
94 #define LCD_D2 0b00000100
95 #define LCD_D3 0b00001000
96 #define LCD_E 0b00010000
97 #define LCD_RW 0b00100000
98 #define LCD_RS 0b01000000
99 #define LCD_LED 0b10000000
100 
101 //**************************************************
102 // PCF8574 Address
103 // PCF8574_ADDRESS_H refers to the enbedded address (PCF8574 model)
104 // PCF8574_ADDRESS_L refers to the A0, A1, A2 pins
105 //**************************************************
106 
107 //PCF8574
108 //#define PCF8574_ADDRESS_H 0x40
109 
110 //PCF8574A
111 #define PCF8574_ADDRESS_H 0x70
112 
113 #define PCF8574_ADDRESS_L 0x00
114 
115 //**************************************************
116 // Constant Definitions
117 
118 #define LEFT 0b00000000
119 #define RIGHT 0b00000100
120 
121 #define TURN_ON_CURSOR 0b00000010
122 #define TURN_OFF_CURSOR 0b00000000
123 
124 #define TURN_ON_LED_LCD 0b00000000
125 #define TURN_OFF_LED_LCD 0b10000000
126 
127 #define BLINKING_ON 0b00000001
128 #define BLINKING_OFF 0b00000000
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