I will post code and you will see where is (I will note it) added change which resolve problem and working 100%
This example was coded for PIC16F84A for my job.
Now I think that this thread (I am not find any fresh thread with solved problem) was solvedCode:Define LCD_DREG PORTB Define LCD_DBIT 4 Define LCD_RSREG PORTB Define LCD_RSBIT 2 Define LCD_EREG PORTB Define LCD_EBIT 3 TempR var word 'DS1820 read Temperature TempNeg var byte 'temperature sign -/+ '*****DS1820 VARS AND SETTINGS******* count_remain var byte 'DS1820 coumter of remain bits count_per_c var byte 'DS1820 counter per C bits symbol DQ = PortA.3 'OneWire data pin '********************************** TrisA = %11111 PortA = 0 TrisB = %00000000 PortB = 0 Main: gosub Read_Temp if TempR=$FFFF then Error gosub Disp_Temp pause 100 goto Main '******DS1820 READING****** Read_Temp: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting If count_remain = 0 Then waitloop OWOut DQ, 1, [$CC, $BE] ' Read the temperature OWIn DQ, 0, [TempR.LowByte, TempR.HighByte, Skip 4, count_remain, count_per_c] if TempR = $FFFF then return if (TempR.HighByte = $FF) and (TempR.LowByte <> 0) then TempNeg = "-" TempR = TempR ^ $FFFF TempR = ((TempR >> 1)*100) - 25 + ((count_per_c + count_remain) * 100) / count_per_c else if (TempR.HighByte < $FF) and (TempR.LowByte <> 0) then TempNeg = "+" TempR = ((TempR >> 1)*100) - 25 + ((count_per_c - count_remain) * 100) / count_per_c else '************************************************ TempR=$0000 ' THIS IS ONLY NEED TO DEFINE !!! '************************************************ endif endif return Disp_Temp: Lcdout $fe, 1, "Temperature: " TempNeg, DEC (TempR / 100),".", DEC2 TempR, 223, "C " return Error: Lcdout $fe, 1, "!!!ERROR!!!", $fe, $C0, "Reading Temp." goto Main end
This code measure temperature with extended resolution (DEC2).
Regards.





Bookmarks