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
PCF8574.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.4
5 Created on Date : 19/03/2011
6 Last update : 16/03/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 These functions allow the user to read/write to the data
39 port of the I2C I/O extender PCF8574.
40 Either PCF8574 or PCF8574A can be used. The user must set the
41 proper internal address (see the define below).
42 
43 PCF8574 Address : 0100xxx0
44 PCF8574A Address : 0111xxx0
45 
46 xxx = A2 A1 A0 (External Address Pins)
47 
48 *******************************************************************************/
49 
50 #ifndef LTLIB_PCF8574_H
51 #define LTLIB_PCF8574_H
52 
53 
54 #ifdef __XC8
55  #include <xc.h>
56 #endif
57 
58 
59 //*****************************************
60 // Library Test
61 //*****************************************
62 
63 #include "LTlib.h"
64 
65 #ifndef LTLIB_I2C_MODULE_H
66  #error The PCF8574 Library requires the "module_I2C" library to be included.
67 #endif
68 
69 //*****************************************
70 // I2C Module Switch
71 //*****************************************
72 #if defined (PCF8574_I2C_MODULE_1) || defined (PCF8574_I2C_MODULE_2)
73 
74 #else
75  #define PCF8574_I2C_MODULE_1
76 #endif
77 
78 #ifdef PCF8574_I2C_MODULE_1
79  #define PCF8574_I2C_open I2C1_open
80  #define PCF8574_I2C_baud_rate I2C1_baud_rate
81  #define PCF8574_I2C_wait_bus_IDLE I2C1_wait_bus_IDLE
82  #define PCF8574_I2C_start_bit I2C1_start_bit
83  #define PCF8574_I2C_check_bus_collision I2C1_check_bus_collision
84  #define PCF8574_I2C_write_byte I2C1_write_byte
85  #define PCF8574_I2C_stop_bit I2C1_stop_bit
86  #define PCF8574_I2C_check_ACK I2C1_check_ACK
87  #define PCF8574_I2C_negative_ACK I2C1_negative_ACK
88  #define PCF8574_I2C_read_byte I2C1_read_byte
89  #define PCF8574_I2C_set_master_as_receiver I2C1_set_master_as_receiver
90 
91 #endif
92 
93 #ifdef PCF8574_I2C_MODULE_2
94  #define PCF8574_I2C_open I2C2_open
95  #define PCF8574_I2C_baud_rate I2C2_baud_rate
96  #define PCF8574_I2C_wait_bus_IDLE I2C2_wait_bus_IDLE
97  #define PCF8574_I2C_start_bit I2C2_start_bit
98  #define PCF8574_I2C_check_bus_collision I2C2_check_bus_collision
99  #define PCF8574_I2C_write_byte I2C2_write_byte
100  #define PCF8574_I2C_stop_bit I2C2_stop_bit
101  #define PCF8574_I2C_check_ACK I2C2_check_ACK
102  #define PCF8574_I2C_negative_ACK I2C2_negative_ACK
103  #define PCF8574_I2C_read_byte I2C2_read_byte
104  #define PCF8574_I2C_set_master_as_receiver I2C2_set_master_as_receiver
105 #endif
106 
107 
108 //*****************************************
109 // Device Settings
110 //*****************************************
111 
112 #define USED_DEVICE_PCF8574 0x40
113 #define USED_DEVICE_PCF8574A 0x70
114 
115 #define PCF8574_INTERNAL_ADDRESS USED_DEVICE_PCF8574
116 
117 
130 void PCF8574_initialize (unsigned int baud_rate_KHz);
131 #define initialize_PCF8574 PCF8574_initialize
132 
133 
151 signed char PCF8574_write_data (unsigned char device_address, unsigned char data );
152 #define write_data_PCF8574 PCF8574_write_data
153 
154 
171 signed char PCF8574_read_data(unsigned char device_address, unsigned char *data);
172 #define read_data_PCF8574 PCF8574_read_data
173 
174 
175 #endif