LTlib LaurTec Library
4.0.1
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
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 : 23/09/2015
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
#ifndef LTLIB_MCP2300X_H
86
#error The LCD_44780_I2C Library requires the "MCP2300x" library to be included.
87
#endif
88
89
//**************************************************
90
// PCF8574 Address
91
// PCF8574_ADDRESS_H refers to the embedded address (PCF8574 model)
92
// PCF8574_ADDRESS_L refers to the A0, A1, A2 pins
93
//**************************************************
94
95
//#define PCF8574
96
//#define PCF8574A
97
#define MCP23008
98
99
#if defined (PCF8574) || defined (PCF8574A) || defined (MCP23008)
100
101
#else
102
#error You must select the I2C device used to drive the LCD (MCP23008,PCF8574, PCF8574A)
103
#endif
104
105
106
//PCF8574
107
#ifdef PCF8574
108
#define DEVICE_ADDRESS_H 0x40
109
#define DEVICE_ADDRESS_L 0x00
110
#define PCF8574_GENERIC
111
#endif
112
113
//PCF8574A
114
#ifdef PCF8574A
115
#define DEVICE_ADDRESS_H 0x70
116
#define DEVICE_ADDRESS_L 0x00
117
#define PCF8574_GENERIC
118
#endif
119
120
#ifdef MCP23008
121
// DEVICE_ADDRESS_H is not needed since the MCP23008 library has it already
122
// so it is just set to 0x00 (not to 0x04)
123
#define DEVICE_ADDRESS_H 0x00
124
#define DEVICE_ADDRESS_L 0x00
125
#endif
126
127
//**************************************************
128
// LCD constants
129
// Each bit is connected to the PCF8574/MC23008
130
//**************************************************
131
132
#define LCD_D0 0b00000001
133
#define LCD_D1 0b00000010
134
#define LCD_D2 0b00000100
135
#define LCD_D3 0b00001000
136
#define LCD_E 0b00010000
137
#define LCD_RW 0b00100000
138
#define LCD_RS 0b01000000
139
#define LCD_LED 0b10000000
140
141
//**************************************************
142
// Constant Definitions
143
144
#define LEFT 0b00000000
145
#define RIGHT 0b00000100
146
#define LCD_LEFT 0b00000000
147
#define LCD_RIGHT 0b00000100
148
149
#define TURN_ON_CURSOR 0b00000010
150
#define TURN_OFF_CURSOR 0b00000000
151
#define LCD_TURN_ON_CURSOR 0b00000010
152
#define LCD_TURN_OFF_CURSOR 0b00000000
153
154
#define BLINKING_ON 0b00000001
155
#define BLINKING_OFF 0b00000000
156
#define LCD_BLINKING_ON 0b00000001
157
#define LCD_BLINKING_OFF 0b00000000
158
159
#define ZERO_CLEANING_ON 0x01
160
#define ZERO_CLEANING_OFF 0x00
161
#define LCD_ZERO_CLEANING_ON 0x01
162
#define LCD_ZERO_CLEANING_OFF 0x00
163
164
//*********************************************************
165
// Depending on the chip a different ON-OFF state is used
166
//*********************************************************
167
#define TURN_ON_LED_LCD 0b00000000
168
#define TURN_OFF_LED_LCD 0b10000000
169
#define LCD_TURN_ON_LED 0b00000000
170
#define LCD_TURN_OFF_LED 0b10000000
171
172
#ifdef MCP23008
173
174
#undef TURN_ON_LED_LCD
175
#undef TURN_OFF_LED_LCD
176
#undef LCD_TURN_ON_LED
177
#undef LCD_TURN_OFF_LED
178
179
#define TURN_ON_LED_LCD 0b10000000
180
#define TURN_OFF_LED_LCD 0b00000000
181
#define LCD_TURN_ON_LED 0b10000000
182
#define LCD_TURN_OFF_LED 0b00000000
183
#endif
184
185
//*********************************************************
186
// Depending on the chip a different baud rate is set
187
//*********************************************************
188
#define BUS_DATA_RATE_LCD 100
189
#define LCD_BUS_DATA_RATE 100
190
191
#ifdef MCP23008
192
193
#undef BUS_DATA_RATE_LCD
194
#undef LCD_BUS_DATA_RATE
195
196
#define BUS_DATA_RATE_LCD 200
197
#define LCD_BUS_DATA_RATE 200
198
#endif
199
200
201
//**************************************************
202
203
204
211
void
LCD_enable_pulse
(
void
);
212
#define enable_pulse_LCD LCD_enable_pulse
213
214
223
void
LCD_send_command
(
unsigned
char
data);
224
#define send_command_LCD LCD_send_command
225
226
231
void
LCD_home
(
void
);
232
#define home_LCD LCD_home
233
234
245
void
LCD_shift
(
unsigned
char
shift,
unsigned
char
number_of_shift);
246
#define shift_LCD LCD_shift
247
248
260
void
LCD_shift_cursor
(
unsigned
char
shift,
unsigned
char
number_of_shift);
261
#define shift_cursor_LCD LCD_shift_cursor
262
263
271
void
goto_line_LCD
(
unsigned
char
line);
272
#define goto_line_LCD LCD_goto_line
273
274
285
void
goto_xy_LCD
(
unsigned
char
x,
unsigned
char
y);
286
#define goto_xy_LCD LCD_goto_xy
287
288
296
void
LCD_write_char
(
unsigned
char
value);
297
#define write_char_LCD LCD_write_char
298
299
309
#ifndef __XC8
310
void
LCD_write_message
(
const
rom
unsigned
char
*buffer);
311
#endif
312
313
#ifdef __XC8
314
void
LCD_write_message
(
const
unsigned
char
*buffer);
315
#endif
316
317
#define write_message_LCD LCD_write_message
318
319
328
void
LCD_write_string
(
unsigned
char
*buffer);
329
#define write_string_LCD LCD_write_string
330
331
347
void
LCD_write_integer
(
int
value,
unsigned
char
number_of_digits,
unsigned
char
zero_cleaning);
348
#define write_integer_LCD LCD_write_integer
349
350
355
void
LCD_clear
(
void
);
356
#define clear_LCD LCD_clear
357
358
370
void
LCD_cursor
(
unsigned
char
active,
unsigned
char
blinking);
371
#define cursor_LCD LCD_cursor
372
373
384
void
LCD_backlight
(
unsigned
char
active);
385
#define backlight_LCD LCD_backlight
386
387
397
void
LCD_initialize
(
unsigned
char
quartz_frequency);
398
#define initialize_LCD LCD_initialize
399
400
401
#endif
LTlib_v_4.0.1
inc
LCD_44780_I2C.h
Generated on Sat Mar 12 2016 11:01:40 for LTlib LaurTec Library by
1.8.3.1