#ifndef defines_i2c #define defines_i2c #include #include "defines.h" #define i2cbitdelay 50 #define I2C_ACK 1 #define I2C_NAK 0 #define SCLPORT PORTD #define SDAPORT PORTD #define SDAPIN 7 #define SCLPIN 8 #define SCLDDR DDRD #define SDADDR DDRD #define i2c_scl_release() bitClear(SCLDDR,SCLPIN); #define i2c_sda_release() bitClear(SDADDR,SDAPIN); // sets SCL low and drives output #define i2c_scl_lo() bitClear(SCLPORT,SCLPIN); bitSet(SCLDDR,SCLPIN); // sets SDA low and drives output #define i2c_sda_lo() bitClear(SDAPORT,SCLPIN); bitSet(SDADDR,SDAPIN); // set SCL high and to input (releases pin) (i.e. change to input,turnon pullup) #define i2c_scl_hi() bitClear(SCLDDR,SCLPIN);bitSet(SCLPORT,SCLPIN); // set SDA high and to input (releases pin) (i.e. change to input,turnon pullup) #define i2c_sda_hi() bitClear(SDADDR,SDAPIN);bitSet(SDAPORT,SDAPIN); void i2c_init(void); void i2c_writebit( uint8_t c ); uint8_t i2c_readbit(void); void i2c_start(void); void i2c_repstart(void); void i2c_stop(void); uint8_t i2c_write( uint8_t c ); uint8_t i2c_read( uint8_t ack ); #endif