PIC18 LaurTec Library  3.3.1
Open Source C Library for PIC18 Microcontrollers based on C18 - XC8 Compilers
 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.1
5 Created on Date : 07/02/2014
6 Last update : 15/12/2014
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 MCP2300X_H
44 #define MCP2300X_H
45 
46 
47 #ifdef __XC8
48  #include <xc.h>
49  #include <i2c.h>
50 
51  #ifndef _PIC18
52  #error The MCP2300X Library supports only PIC18 devices
53  #endif
54 #endif
55 
56 #include <i2c.h>
57 
58 
59 //*****************************************
60 // Constants definition
61 //*****************************************
62 
63 #define INTERNAL_ADDRESS 0x40
64 
65 #define MCP2300x_IODIR 0x00
66 #define MCP2300x_IPOL 0x01
67 #define MCP2300x_GPINTEN 0x02
68 #define MCP2300x_DEFVAL 0x03
69 #define MCP2300x_INTCON 0x04
70 #define MCP2300x_IOCON 0x05
71 #define MCP2300x_GPPU 0x06
72 #define MCP2300x_INTF 0x07
73 #define MCP2300x_INTCAP 0x08
74 #define MCP2300x_GPIO 0x09
75 #define MCP2300x_OLAT 0x0A
76 
77 
78 
79 #define MCP2300x_SEQOP 0b00100000
80 #define MCP2300x_DISSLW 0b00010000
81 #define MCP2300x_HAEN 0b00001000 // Not implemented by I2C interface
82 #define MCP2300x_ODR 0b00000100
83 #define MCP2300x_INTPOL 0b00000010
84 
85 #define MCP2300x_CLEAR_REG 0b00000000
86 
87 
103 void MCP2300x_initialize (unsigned char crystal_frequency_MHz, unsigned int baud_rate_KHz);
104 #define initialize_MC2300x MCP2300x_initialize
105 
106 
125 signed char MCP2300x_set_register (unsigned char device_address, unsigned char register_add, unsigned char data );
126 #define set_register_MCP2300x MCP2300x_set_register
127 
128 
142 unsigned char MCP2300x_get_register (unsigned char device_address, unsigned char register_add);
143 #define get_register_MCP2300x MCP2300x_get_register
144 
145 
162 signed char MCP2300x_set_port_direction (unsigned char device_address, unsigned char direction);
163 #define set_port_direction_MCP2300x MCP2300x_set_port_direction
164 
165 
176 unsigned char MCP2300x_get_port_value (unsigned char device_address);
177 #define get_port_value_MCP2300x MCP2300x_get_port_value
178 
179 
196 signed char MCP2300x_set_port_value (unsigned char device_address, unsigned char value);
197 #define set_port_value_MCP2300x MCP2300x_set_port_value
198 
199 
214 signed char MCP2300x_set_port_polarity (unsigned char device_address, unsigned char value);
215 #define set_port_polarity_MCP2300x MCP2300x_set_port_polarity
216 
217 
234 signed char MCP2300x_set_port_pull_up_resistor (unsigned char device_address, unsigned char value);
235 #define set_port_pull_up_resistor_MCP2300x MCP2300x_set_port_pull_up_resistor
236 
237 
257 signed char MCP2300x_set_port_interrupt (unsigned char device_address, unsigned char value);
258 #define set_port_interrupt_MCP2300x MCP2300x_set_port_interrupt
259 
260 
278 signed char MCP2300x_set_port_configuration (unsigned char device_address, unsigned char value);
279 #define set_port_configuration_MCP2300x MCP2300x_set_port_configuration
280 
281 
298 signed char MCP2300x_set_interrupt_compare_value (unsigned char device_address, unsigned char value);
299 #define set_interrupt_compare_value_MCP2300x MCP2300x_set_interrupt_compare_value
300 
301 
318 signed char MCP2300x_set_interrupt_compare_enable (unsigned char device_address, unsigned char value);
319 #define set_interrupt_compare_enable_MCP2300x MCP2300x_set_interrupt_compare_enable
320 
321 
333 unsigned char MCP2300x_get_port_interrupt_flag (unsigned char device_address);
334 #define get_port_interrupt_flag_MCP2300x MCP2300x_get_port_interrupt_flag
335 
336 
350 unsigned char MCP2300x_get_port_interrupt_capture (unsigned char device_address);
351 #define get_port_interrupt_capture_MCP2300x MCP2300x_get_port_interrupt_capture
352 
353 
354 #endif