#include <8051.h>
#include <stdint.h>
#include "i2c.h"
#define I2C_SDAT P3_4
#define I2C_SCLK P3_3
void i2c_init()
{ /* GPIO port initial */
I2C_SDAT = 1;
I2C_SCLK = 1;
}
void i2c_delay()
{
volatile char i = 20;
while(i--);
void i2c_start()
I2C_SDAT = 0;
i2c_delay();
I2C_SCLK = 0;
void i2c_stop()
void i2c_write(uint8_t data)
int i;
for(i = 0; i < 8; i++)
data <<= 1;
I2C_SDAT = CY;
uint8_t i2c_read()
uint8_t ret = 0;
ret <<= 1;
if(I2C_SDAT)
ret |= 0x01;
return ret;
bool i2c_read_ack()
bool status;
status = I2C_SDAT;
return !status;
bool i2c_read_nak()
return !i2c_read_ack();