Exemplo n.º 1
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();
}
Exemplo 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;
}
Exemplo n.º 3
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;
}