Ejemplo n.º 1
0
// write a byte to the I2C slave device
//
unsigned char I2C_Write(unsigned char c)
{
    for (char i = 0; i < 8; i++)
    {
        I2C_WriteBit(c & 128);

        c <<= 1;
    }


    I2C_WriteBit(0);
    _delay_us(I2C_DELAY);
    _delay_us(I2C_DELAY);

    // _delay_us(I2C_DELAY);
    //return I2C_ReadBit();
    return 0;
}
Ejemplo n.º 2
0
//! read a byte from the I2C slave device
unsigned char I2C_Read( unsigned char ack )
{
  unsigned char res = 0;
  char i;
  
  for (i=0;i<8;i++){
    res <<= 1;
    res |= I2C_ReadBit();  
  }
  
  if( ack > 0)
    I2C_WriteBit(0);
  else
    I2C_WriteBit(1);
  
  I2CDELAY(1);
  
  return res;
}
Ejemplo n.º 3
0
//! write a byte to the I2C slave device
unsigned char I2C_Write( unsigned char c )
{
  char i;
  for (i=0;i<8;i++){
    I2C_WriteBit( c & 0x80 );
    c<<=1;
  }
  
  return I2C_ReadBit_Wait();
}
Ejemplo n.º 4
0
// read a byte from the I2C slave device
//
uint8_t I2C_Read(uint8_t ack )
{
  uint8_t res = 0;
  uint8_t i = 0;
  for (i=0;i<8;i++) {
      res <<= 1;
      res |= I2C_ReadBit();
  }

  if ( ack > 0) 
    I2C_WriteBit( 0 );
  else 
    I2C_WriteBit( 1 );
  

  _delay_ms(1);

  return res;
} 
Ejemplo n.º 5
0
// write a byte to the I2C slave device
//
unsigned char I2C_Write( unsigned char c )
{
  uint8_t i = 0;
  for (i=0;i<8;i++) {
    I2C_WriteBit( c & 128 );
    c<<=1;
  }

  return I2C_ReadBit();
}