#ifndef _I2C_H #define _I2C_H /* PIC18 I2C peripheral library header */ /* SSPCON1 REGISTER */ #define SSPENB 0b00100000 /* Enable serial port and configures SCK, SDO, SDI */ #define SLAVE_7 0b00000110 /* I2C Slave mode, 7-bit address */ #define SLAVE_10 0b00000111 /* I2C Slave mode, 10-bit address */ #define MASTER 0b00001000 /* I2C Master mode */ #define MASTER_FIRMW 0b00001011 #define SLAVE_7_STSP_INT 0b00001110 #define SLAVE_10_STSP_INT 0b00001111 /* SSPSTAT REGISTER */ #define SLEW_OFF 0b11000000 /* Slew rate disabled for 100kHz mode */ #define SLEW_ON 0b00000000 /* Slew rate enabled for 400kHz mode */ /* StopI2C * Generate bus stop condition */ #define StopI2C() PEN=1 /* StartI2C * Generate bus start condition */ #define StartI2C() SEN=1 /* RestartI2C * Generate bus restart condition */ #define RestartI2C() RSEN=1 /* NotAckI2C * Generate bus Not ACK condition */ #define NotAckI2C() ACKDT=1, ACKEN=1 /* AckI2C * Generate bus ACK condition */ #define AckI2C() ACKDT=0, ACKEN=1 /* Idle I2C * Test if I2C module is idle */ #define IdleI2C() while ((SSPCON2 & 0x1F) | (RW)) /* CloseI2C * Disable SPI module */ #define CloseI2C() SSPCON1 &=0xDF /* OpenI2C * Configure SSP module for use with I2C EEPROM or I2C bus device. */ void OpenI2C( unsigned char sync_mode, unsigned char slew ); /* DataRdyI2C * Test if SSPBUF register is full */ #define DataRdyI2C() (BF) /* ReadI2C * Read byte from SSPBUF register */ unsigned char ReadI2C( void ); /* GetcI2C * Read byte from SSPBUF register */ #define getcI2C ReadI2C /* WriteI2C * Write byte to SSPBUF register */ unsigned char WriteI2C( unsigned char data_out ); /* putcI2C * Write byte to SSPBUF register */ #define putcI2C WriteI2C /* getsI2C * Read in a string from I2C module */ unsigned char getsI2C( unsigned char *rdptr, unsigned char length ); /* putsI2C * Write a string to I2C module */ signed char putsI2C( unsigned char *wrptr ); #define I2C_SCL TRISB1 #define I2C_SDA TRISB0 #endif