nisam terao taj termometar na hitech-u ali sam pricao sa njim koristeci mnoge druge ... obrati paznju da vecina biblioteka koristi isti kod za pricu sa svim 18x20 ... problem je sto se rezultat razlicito interpretira ako je 18S20 (9bita rezultat) ili 18B20 (12 bita rezultat) ili neki treci ...
tipicna rutina za citanje (E2 je pin za one wire na primer)
Code:
unsigned in16 temp;
Ow_Reset(&PORTE, 2);
Ow_Write(&PORTE, 2, 0xCC);
Ow_Write(&PORTE, 2, 0x44);
Delay_us(120);
Ow_Reset(&PORTE, 2);
Ow_Write(&PORTE, 2, 0xCC);
Ow_Write(&PORTE, 2, 0xBE);
temp = Ow_Read(&PORTE, 2);
temp = (Ow_Read(&PORTE, 2) << 8) + temp;
(OW_* je mikroc one wire biblioteka, hitech ima svoju)
e sada je fora samo izvadidi vrednost iz temp varijable i to je razlicito vezano za velicinu rezultata
ovo ti je primer kako da procitas vrednost i upises u txt array koji onda bacis na display
(int8 je 1byte integer, int16 je 2 byte integer, char je 1byte integer..)
Code:
// Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
// 18S20: 9
// 18B20: 12
const unsigned int8 TEMP_RESOLUTION = 9;
const unsigned int8 RES_SHIFT = TEMP_RESOLUTION - 8;
char temp_whole;
unsigned int16 temp_fraction;
// check if temperature is negative
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
}
// extract temp_whole
temp_whole = temp2write >> RES_SHIFT ;
// convert temp_whole to characters
if (temp_whole/100)
text[0] = temp_whole/100 + 48;
else
text[0] = '0';
text[1] = (temp_whole/10)%10 + 48; // Extract tens digit
text[2] = temp_whole%10 + 48; // Extract ones digit
// extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
// convert temp_fraction to characters
text[4] = temp_fraction/1000 + 48; // Extract thousands digit
text[5] = (temp_fraction/100)%10 + 48; // Extract hundreds digit
text[6] = (temp_fraction/10)%10 + 48; // Extract tens digit
text[7] = temp_fraction%10 + 48; // Extract ones digit