00001
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #ifndef I2C_H
00068 #define I2C_H
00069
00070
00071 #define READ 1
00072 #define WRITE 0
00073 #define ACK 1
00074 #define NAK 0
00075
00076
00077
00078 #define SDA PC3
00079 #define SCL PC2
00080 #define SDA_DDR DDRC
00081 #define SCL_DDR DDRC
00082 #define SDA_PIN PINC
00083 #define SCL_PIN PINC
00084 #define SDA_PORT PORTC
00085 #define SCL_PORT PORTC
00086
00087 #define NOP asm volatile("nop")
00088 #define QDEL NOP; NOP; NOP; NOP; NOP
00089 #define HDEL QDEL; QDEL
00090
00091 #define SDA_HI SDA_PORT |= (1 << SDA)
00092 #define SDA_LO SDA_PORT &= ~(1 << SDA)
00093
00094 #define SCL_HI SCL_PORT |= (1 << SCL)
00095 #define SCL_LO SCL_PORT &= ~(1 << SCL)
00096
00097 #define SCL_TOGGLE HDEL; SCL_HI; HDEL; SCL_LO
00098 #define I2C_START SDA_LO; QDEL; SCL_LO
00099 #define I2C_STOP HDEL; SCL_HI; QDEL; SDA_HI; HDEL
00100
00101
00102
00103 void InitI2C(void);
00104 unsigned char WriteI2C(unsigned char byte);
00105 unsigned char ReadI2C(unsigned char nak);
00106 unsigned char StartI2C(unsigned char device);
00107 void StopI2C(void);
00108
00109 #endif