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
MCP2300x.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3 Author : Mauro Laurenti
4 Version : 1.2
5 Created on Date : 07/02/2014
6 Last update : 16/03/2016
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 These functions allow the user to read/write to the data
39 port of the I2C I/O expander MCP2300x device.
40 
41 *******************************************************************************/
42 
43 #ifndef LTLIB_MCP2300X_H
44 #define LTLIB_MCP2300X_H
45 
46 #ifdef __XC8
47  #include <xc.h>
48 #endif
49 
50 //*****************************************
51 // Library Test
52 //*****************************************
53 #include "LTlib.h"
54 
55 #ifndef LTLIB_I2C_MODULE_H
56  #error The MCP2300X Library requires the "module_I2C" library to be included.
57 #endif
58 
59 //*****************************************
60 // I2C Module Switch
61 //*****************************************
62 #if defined (MCP2300X_I2C_MODULE_1) || defined (MCP2300X_I2C_MODULE_2)
63 
64 #else
65  #define MCP2300X_I2C_MODULE_1
66 #endif
67 
68 
69 #ifdef MCP2300X_I2C_MODULE_1
70  #define MCP2300X_I2C_open I2C1_open
71  #define MCP2300X_I2C_baud_rate I2C1_baud_rate
72  #define MCP2300X_I2C_write_byte_to_external_device I2C1_write_byte_to_external_device
73  #define MCP2300X_I2C_read_byte_from_external_device I2C1_read_byte_from_external_device
74 #endif
75 
76 #ifdef MCP2300X_I2C_MODULE_2
77  #define MCP2300X_I2C_open I2C2_open
78  #define MCP2300X_I2C_baud_rate I2C2_baud_rate
79  #define MCP2300X_I2C_write_byte_to_external_device I2C2_write_byte_to_external_device
80  #define MCP2300X_I2C_read_byte_from_external_device I2C2_read_byte_from_external_device
81 #endif
82 
83 //*****************************************
84 // Device settings
85 //*****************************************
86 
87 #define MCP2300X_INTERNAL_ADDRESS 0x40
88 
89 //*****************************************
90 // Constants definition
91 //*****************************************
92 
93 #define MCP2300x_IODIR 0x00
94 #define MCP2300x_IPOL 0x01
95 #define MCP2300x_GPINTEN 0x02
96 #define MCP2300x_DEFVAL 0x03
97 #define MCP2300x_INTCON 0x04
98 #define MCP2300x_IOCON 0x05
99 #define MCP2300x_GPPU 0x06
100 #define MCP2300x_INTF 0x07
101 #define MCP2300x_INTCAP 0x08
102 #define MCP2300x_GPIO 0x09
103 #define MCP2300x_OLAT 0x0A
104 
105 
106 #define MCP2300x_SEQOP 0b00100000
107 #define MCP2300x_DISSLW 0b00010000
108 #define MCP2300x_HAEN 0b00001000 // Not implemented by I2C interface
109 #define MCP2300x_ODR 0b00000100
110 #define MCP2300x_INTPOL 0b00000010
111 
112 #define MCP2300x_CLEAR_REG 0b00000000
113 
114 
127 void MCP2300x_initialize (unsigned int baud_rate_KHz);
128 #define initialize_MC2300x MCP2300x_initialize
129 
130 
149 signed char MCP2300x_set_register (unsigned char device_address, unsigned char register_add, unsigned char data );
150 #define set_register_MCP2300x MCP2300x_set_register
151 
152 
166 unsigned char MCP2300x_get_register (unsigned char device_address, unsigned char register_add);
167 #define get_register_MCP2300x MCP2300x_get_register
168 
169 
186 signed char MCP2300x_set_port_direction (unsigned char device_address, unsigned char direction);
187 #define set_port_direction_MCP2300x MCP2300x_set_port_direction
188 
189 
200 unsigned char MCP2300x_get_port_value (unsigned char device_address);
201 #define get_port_value_MCP2300x MCP2300x_get_port_value
202 
203 
220 signed char MCP2300x_set_port_value (unsigned char device_address, unsigned char value);
221 #define set_port_value_MCP2300x MCP2300x_set_port_value
222 
223 
238 signed char MCP2300x_set_port_polarity (unsigned char device_address, unsigned char value);
239 #define set_port_polarity_MCP2300x MCP2300x_set_port_polarity
240 
241 
258 signed char MCP2300x_set_port_pull_up_resistor (unsigned char device_address, unsigned char value);
259 #define set_port_pull_up_resistor_MCP2300x MCP2300x_set_port_pull_up_resistor
260 
261 
281 signed char MCP2300x_set_port_interrupt (unsigned char device_address, unsigned char value);
282 #define set_port_interrupt_MCP2300x MCP2300x_set_port_interrupt
283 
284 
302 signed char MCP2300x_set_port_configuration (unsigned char device_address, unsigned char value);
303 #define set_port_configuration_MCP2300x MCP2300x_set_port_configuration
304 
305 
322 signed char MCP2300x_set_interrupt_compare_value (unsigned char device_address, unsigned char value);
323 #define set_interrupt_compare_value_MCP2300x MCP2300x_set_interrupt_compare_value
324 
325 
342 signed char MCP2300x_set_interrupt_compare_enable (unsigned char device_address, unsigned char value);
343 #define set_interrupt_compare_enable_MCP2300x MCP2300x_set_interrupt_compare_enable
344 
345 
357 unsigned char MCP2300x_get_port_interrupt_flag (unsigned char device_address);
358 #define get_port_interrupt_flag_MCP2300x MCP2300x_get_port_interrupt_flag
359 
360 
374 unsigned char MCP2300x_get_port_interrupt_capture (unsigned char device_address);
375 #define get_port_interrupt_capture_MCP2300x MCP2300x_get_port_interrupt_capture
376 
377 
378 #endif