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 File Reference
#include <i2c.h>

Go to the source code of this file.

Macros

#define INTERNAL_ADDRESS   0x40
 
#define IODIR   0x00
 
#define IPOL   0x01
 
#define GPINTEN   0x02
 
#define DEFVAL   0x03
 
#define INTCON   0x04
 
#define IOCON   0x05
 
#define GPPU   0x06
 
#define INTF   0x07
 
#define INTCAP   0x08
 
#define GPIO   0x09
 
#define OLAT   0x0A
 
#define SEQOP   0b00100000
 
#define DISSLW   0b00010000
 
#define HAEN   0b00001000
 
#define ODR   0b00000100
 
#define INTPOL   0b00000010
 
#define CLEAR_REG   0b00000000
 

Functions

void initialize_MC2300x (unsigned char crystal_frequency_MHz, unsigned int baud_rate_KHz)
 
signed char set_register_MCP2300x (unsigned char device_address, unsigned char register_add, unsigned char data)
 
unsigned char get_register_MCP2300x (unsigned char device_address, unsigned char register_add)
 
signed char set_port_direction_MCP2300x (unsigned char device_address, unsigned char direction)
 
unsigned char get_port_value_MCP2300x (unsigned char device_address)
 
signed char set_port_value_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_port_polarity_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_port_pull_up_resistor_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_port_interrupt_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_port_configuration_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_interrupt_compare_value_MCP2300x (unsigned char device_address, unsigned char value)
 
signed char set_interrupt_compare_enable_MCP2300x (unsigned char device_address, unsigned char value)
 
unsigned char get_port_interrupt_flag_MCP2300x (unsigned char device_address)
 
unsigned char get_port_interrupt_capture_MCP2300x (unsigned char device_address)
 

Macro Definition Documentation

#define CLEAR_REG   0b00000000

Definition at line 85 of file MCP2300x.h.

#define DEFVAL   0x03

Definition at line 68 of file MCP2300x.h.

#define DISSLW   0b00010000

Definition at line 80 of file MCP2300x.h.

#define GPINTEN   0x02

Definition at line 67 of file MCP2300x.h.

#define GPIO   0x09

Definition at line 74 of file MCP2300x.h.

#define GPPU   0x06

Definition at line 71 of file MCP2300x.h.

#define HAEN   0b00001000

Definition at line 81 of file MCP2300x.h.

#define INTCAP   0x08

Definition at line 73 of file MCP2300x.h.

#define INTCON   0x04

Definition at line 69 of file MCP2300x.h.

#define INTERNAL_ADDRESS   0x40

Definition at line 63 of file MCP2300x.h.

#define INTF   0x07

Definition at line 72 of file MCP2300x.h.

#define INTPOL   0b00000010

Definition at line 83 of file MCP2300x.h.

#define IOCON   0x05

Definition at line 70 of file MCP2300x.h.

#define IODIR   0x00

Definition at line 65 of file MCP2300x.h.

#define IPOL   0x01

Definition at line 66 of file MCP2300x.h.

#define ODR   0b00000100

Definition at line 82 of file MCP2300x.h.

#define OLAT   0x0A

Definition at line 75 of file MCP2300x.h.

#define SEQOP   0b00100000

Definition at line 79 of file MCP2300x.h.

Function Documentation

unsigned char get_port_interrupt_capture_MCP2300x ( unsigned char  device_address)

This function reads from the INTCAP register, enabling the read of the pin flags that caused the interrupt. In particular INTCAP register it captures the value at the time of the interrupt so it may differ from the value of INTF register.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
Returns
Content of the interrupt flag register captured at the time of the interrupt event.
Note
This register is read only. A bit set to 1 it means that the input has generated an interrupt.

Definition at line 187 of file MCP2300x.c.

References get_register_MCP2300x(), and INTCAP.

unsigned char get_port_interrupt_flag_MCP2300x ( unsigned char  device_address)

This function reads from the INTF register, enabling the read of the pin flags that caused the interrupt.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
Returns
Content of the interrupt flag register.
Note
This register is read only. A bit set to 1 it means that the input has generated an interrupt.

Definition at line 178 of file MCP2300x.c.

References get_register_MCP2300x(), and INTF.

unsigned char get_port_value_MCP2300x ( unsigned char  device_address)

This function reads from the GPIO register, which is equivalent to read the value of the external pins.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
Returns
It returns the values of the external pins.

Definition at line 127 of file MCP2300x.c.

References get_register_MCP2300x(), and GPIO.

unsigned char get_register_MCP2300x ( unsigned char  device_address,
unsigned char  register_add 
)

This function reads from any register of the MCP2300x device.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
register_addAddress of the register that must be written.
Returns
Content out of the pointed register.
Note
For the register address you can use the name of the register as in the data sheet. The same name, upper case, are defined in the header file.

Definition at line 79 of file MCP2300x.c.

References INTERNAL_ADDRESS.

void initialize_MC2300x ( unsigned char  crystal_frequency_MHz,
unsigned int  baud_rate_KHz 
)

This function initialize the I2C module accordingly to the clock and baud rate.

Parameters
crystal_frequency_MHzClock frequency expressed in MHz
baud_rate_KHzBaud rate expressed in KHz
Returns
Note
If other devices are connected on the I2C bus the baud rate would be changed by the function. Among several call from different device initializations, only the last one will be reflected in the I2C module configuration.

Definition at line 53 of file MCP2300x.c.

signed char set_interrupt_compare_enable_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into INTCON register, which is equivalent to select the interrupt modality. A zero sets an interrupt on pin change, while a 1 enable the comparison with the DEFVAL Register.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueValue that enables the pins where the comparison must be activated.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
Refer to the data sheet for more details on the interrupt on change and on comparison with DEFVAL register

Definition at line 169 of file MCP2300x.c.

References INTCON, and set_register_MCP2300x().

signed char set_interrupt_compare_value_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into DEFVAL register, which is equivalent to set the value for the interrupt comparison. If bit 2 is set to 1 a 0 into pin 2 will trigger the interrupt.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueByte that reflects the value of interest to be used for the comparison.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
Refer to the data sheet for more details on the interrupt on change and on comparison with DEFVAL register.

Definition at line 160 of file MCP2300x.c.

References DEFVAL, and set_register_MCP2300x().

signed char set_port_configuration_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into IOCON register, enabling some internal configurations. SEQOP, DISSLW, ODR, INTPOL

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueValue that reflects the pins where the comparison must be enabled.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
Refer to the data sheet for more details on available options. Constants are defined in the to enable and easy use of the settings.

Definition at line 153 of file MCP2300x.c.

References IOCON, and set_register_MCP2300x().

signed char set_port_direction_MCP2300x ( unsigned char  device_address,
unsigned char  direction 
)

This function writes into IODIR register, defining the direction of the pin. A 1 in a bit is equivalent to set the corresponding pin as input, while a 0 sets it to Output.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
directionValue that defines the direction of each pin.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision

Definition at line 91 of file MCP2300x.c.

References IODIR, and set_register_MCP2300x().

signed char set_port_interrupt_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into GPINTEN register, which is equivalent to activate the interrupts. A bit set to 1 enables the interrupt to the corresponding pin. This option affects only pins that are set as inputs.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueValue to enable the pins where the interrupt must be activated.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Warning
The interrupt of the MCP2300x device must be enabled before the Microcontroller General Interrupt Enable. A dummy read of the GPIO register is internally performed to clear any pending interrupt.

Definition at line 137 of file MCP2300x.c.

References get_register_MCP2300x(), GPINTEN, GPIO, and set_register_MCP2300x().

signed char set_port_polarity_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into IPOL register, which defines the polarity of the input pins.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueThe value sets the corresponding pin with an inverting value (input only).
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision

Definition at line 109 of file MCP2300x.c.

References IPOL, and set_register_MCP2300x().

signed char set_port_pull_up_resistor_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into GPPU register, which is equivalent to activate the pull-up resistor. A bit set to 1 enables the pull-up resistor to the corresponding pin. This option affect only the pins that are set as inputs.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueValue to enable the pins where the pull-up resistor must be activated.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision

Definition at line 118 of file MCP2300x.c.

References GPPU, and set_register_MCP2300x().

signed char set_port_value_MCP2300x ( unsigned char  device_address,
unsigned char  value 
)

This function writes into the GPIO register, which is equivalent to write to the output port.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
valueValue that must be written to the output port.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
Writing to the output port affects only the pins that are set as output.

Definition at line 100 of file MCP2300x.c.

References GPIO, and set_register_MCP2300x().

signed char set_register_MCP2300x ( unsigned char  device_address,
unsigned char  register_add,
unsigned char  data 
)

This function writes into any register of the MCP2300x device.

Parameters
device_addressHardware Address of the device (A0, A1, A2 only) [min: 0, max: 7].
register_addAddress of the register that must be written.
dataData that must be written into the register.
Returns
status 1: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
For the register address you can use the name of the register as in the data sheet. The same name, upper case, are defined in the header file.

Definition at line 64 of file MCP2300x.c.

References INTERNAL_ADDRESS.