Может кому сгодится.
i2c.h
#ifndef I2C_H_ #define I2C_H_ #include "main.h" void I2C_Ini(void); void I2C_StartCondition(void); void I2C_StopCondition(void); void I2C_SendByte(unsigned char byte); void PCF8574AT_SendByte(unsigned char data,unsigned char adres); #endif /* I2C_H_ */
i2c.c
#include "i2c.h" void I2C_Ini(void) { TWBR = 0X20; } void I2C_StartCondition(void) { TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); while(!(TWCR&(1<<TWINT))); } void I2C_StopCondition(void) { TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); } void I2C_SendByte(unsigned char byte) { TWDR = byte; TWCR = (1<<TWINT)|(1<<TWEN); while(!(TWCR&(1<<TWINT))); } void PCF8574AT_SendByte(unsigned char data, unsigned char adres) { I2C_StartCondition(); I2C_SendByte(adres<<1); I2C_SendByte(data); I2C_StopCondition(); }