I tried this code below :
temperature Var Word ' Temperature storage
count_remain Var Byte ' Count remaining
count_per_c Var Byte ' Count per degree C
DQ Var PORTD.6 ' One-wire data pin
loop :
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
OWIn DQ, 4, [count_remain] ' Check for still busy converting
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
goto loop
It worked well when i use crystal 6 Mhz , OSC_HS . Data from DS1820 was ok.
But when i used crystal 6 Mhz , OSC_HS or higher Mhz , OSC_HS . Data from DS1820 allway 54.11'C .
Maybe the speed of PIC is too high but I need the high speed process from PIC . How can i config DS1820 when connect to High-speed PIC ?
Who can help me to fix this problem ?
Many thanks !
Sory for my English.
Bookmarks