Caros amigos estou com um problema com o LM 35 nessa função;a leitura so fica em zero graus
void OneWireOutByte (int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for (n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite (Pin, LOW);
pinMode (Pin, OUTPUT);
delayMicroseconds (5);
pinMode (Pin, INPUT);
delayMicroseconds (60);
}
else
{
digitalWrite (Pin, LOW);
pinMode (Pin, OUTPUT);
delayMicroseconds (60);
pinMode (Pin, INPUT);
}
d = d>>1; // now the next bit is in the least sig bit position.
}
}
byte OneWireInByte (int Pin) // read byte, least sig byte first
{
byte d, n, b;
for (n=0; n<8; n++)
{
digitalWrite (Pin, LOW);
pinMode (Pin, OUTPUT);
delayMicroseconds (5);
pinMode (Pin, INPUT);
delayMicroseconds (5);
b = digitalRead (Pin);
delayMicroseconds (50);
d = (d >> 1) | (b7); // shift d to right and insert b in most sig bit position
}
return (d);
}
void getCurrentTemp (char *temp)
{
int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
OneWireReset (REF_PIN);
OneWireOutByte (REF_PIN, 0xcc);
OneWireOutByte (REF_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset (REF_PIN);
OneWireOutByte (REF_PIN, 0xcc);
OneWireOutByte (REF_PIN, 0xbe);
LowByte = OneWireInByte (REF_PIN);
HighByte = OneWireInByte (REF_PIN);
TReading = (HighByte 8) + LowByte;
sign = TReading & 0x8000; // test most sig bit
if (sign) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
whole = Tc_100 / 100; // separate off the whole and fractional portions
fract = Tc_100 % 100;
if (sign) {
temp[0] = '-';
} else {
temp[0] = '+';
}
if (whole/100 == 0) {
temp[1] = ' ';
} else {
temp[1] = whole/100+'0';
}
temp[2] = (whole-(whole/100)*100)/10 +'0' ;
temp[3] = whole-(whole/10)*10 +'0';
temp[4] = '.';
temp[5] = fract/10 +'0';
temp[6] = fract-(fract/10)*10 +'0';
temp[7] = '\0';
}
Tags:
As respostas para este tópico estão encerradas.
Oi CF, boa noite,
estas funções você postou são somente partes de um código? certo?
Pelo que identifiquei elas são funções para um dispositivo de interface tipo "onewire".
O LM35 não é do tipo "onewire"", e sim de leitura analógica, e não deve funcionar com estas funções.
http://www.ti.com/lit/ds/symlink/lm35.pdf
A propósito, de uma lida no tópico
http://labdegaragem.com/forum/topics/sugest-o-de-como-postar
Rui
Olá Carlos,
Se sua intenção é apenas medir temperatura em Celsius ou Fahrenheit, segue link de um vídeo no meu canal do YT, na descrição abaixo do vídeo você encontra o link para o código que utilizei.
https://www.youtube.com/watch?v=uT2D0OBhpLk&feature=youtu.be
Abs.
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por