- Código: Selecionar todos
#ifndef DAL_SCL
#define DAL_SCL PIN_C3
#define DAL_SDA PIN_C4
#endif
#use i2c(master, sda=DAL_SDA, scl=DAL_SCL, slow)
#define sensor1 0x90
#define sensor2 0x92
int16 temp=0;
void init_temp(int sensor) {
output_high(DAL_SDA);
output_high(DAL_SCL);
i2c_start();
i2c_write(sensor);
i2c_write(0x01);
i2c_write(0x00);
i2c_stop();
}
int16 le_temperatura(int sensor) {
int8 temph=0, templ=0;
i2c_start();
i2c_write(sensor);
i2c_write(0x00);
delay_ms(500); //conforme datasheet, sao 500ms para conversao
i2c_stop();
i2c_start();
i2c_write(sensor | 0x01); //w=1=leitura
temph=i2c_read();
templ=i2c_read(0); //sem acknoledge
i2c_stop();
temp=make16(temph,templ);
temp=temp>>3;
if (bit_test(temph,4)) //se for temperatura negativa
{
temp=temp^0x0FFF;
temp=(temp&0xFFF)+1;
temp=temp*-10;
temp=temp>>4;
}
else //se for temperatura positiva
{
temp=temp*10;
temp=temp>>4;
}
return(temp);
}