PIC18 LaurTec Library  3.2.0
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.0
5 Created on Date : 07/02/2014
6 Last update : 07/02/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 IODIR 0x00
66 #define IPOL 0x01
67 #define GPINTEN 0x02
68 #define DEFVAL 0x03
69 #define INTCON 0x04
70 #define IOCON 0x05
71 #define GPPU 0x06
72 #define INTF 0x07
73 #define INTCAP 0x08
74 #define GPIO 0x09
75 #define OLAT 0x0A
76 
77 
78 
79 #define SEQOP 0b00100000
80 #define DISSLW 0b00010000
81 #define HAEN 0b00001000 // Not implemented by I2C interface
82 #define ODR 0b00000100
83 #define INTPOL 0b00000010
84 
85 #define CLEAR_REG 0b00000000
86 
87 
103 void initialize_MC2300x (unsigned char crystal_frequency_MHz, unsigned int baud_rate_KHz);
104 
105 
124 signed char set_register_MCP2300x (unsigned char device_address, unsigned char register_add, unsigned char data );
125 
126 
140 unsigned char get_register_MCP2300x (unsigned char device_address, unsigned char register_add);
141 
142 
159 signed char set_port_direction_MCP2300x (unsigned char device_address, unsigned char direction);
160 
161 
172 unsigned char get_port_value_MCP2300x (unsigned char device_address);
173 
174 
191 signed char set_port_value_MCP2300x (unsigned char device_address, unsigned char value);
192 
193 
208 signed char set_port_polarity_MCP2300x (unsigned char device_address, unsigned char value);
209 
210 
227 signed char set_port_pull_up_resistor_MCP2300x (unsigned char device_address, unsigned char value);
228 
229 
249 signed char set_port_interrupt_MCP2300x (unsigned char device_address, unsigned char value);
250 
251 
269 signed char set_port_configuration_MCP2300x (unsigned char device_address, unsigned char value);
270 
271 
288 signed char set_interrupt_compare_value_MCP2300x (unsigned char device_address, unsigned char value);
289 
290 
307 signed char set_interrupt_compare_enable_MCP2300x (unsigned char device_address, unsigned char value);
308 
309 
321 unsigned char get_port_interrupt_flag_MCP2300x (unsigned char device_address);
322 
323 
337 unsigned char get_port_interrupt_capture_MCP2300x (unsigned char device_address);
338 
339 #endif