Code:
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_OFF
@ DEVICE pic12F675, PWRT_OFF
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_OFF
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF
dEFINE OSC 4
DEFINE OSCCAL_1K 1 ' osc calibration
Ansel = 0 ' Analog off
CMCON = 7 ' Comparators off
ADCON0 = 7 ' Configure A/D channel
WPU = %000000 'dISABLE wEAK pULLUPS
TRISIO = %10010 ' Set all I/O's to outputs
temperature var word 'DS1820 read Temperature
TempNeg var byte 'temperature sign -/+
Sign VAR BIT
TempC VAR WORD
'*****DS1820 VARS AND SETTINGS*******
count_remain var byte 'DS1820 coumter of remain bits
count_per_c var byte 'DS1820 counter per C bits
'**********************************
DQ Var GPIO.2 ' One-wire data pin
PAUSE 1000
Main:
GOTO Read_Temp
'******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, [temperature.LowByte, temperature.HighByte, Skip 4, count_remain, count_per_c]
' SEROUT2 GPIO.0,16468, ["+Raw", IBIN16 temperature,13,10]
Sign = temperature.15
' SEROUT2 GPIO.0,16468, ["SIGN", DEC Sign,13,10]
' SEROUT2 GPIO.0,16468, ["+REMAIN", DEC count_remain,13,10]
' SEROUT2 GPIO.0,16468, ["+PERC", DEC count_per_c,13,10]
PAUSE 2000
if (temperature.HighByte = $FF) and (temperature.LowByte <> 0) then
TempNeg = "-"
temperature = temperature ^ $FFFF
temperature = (((temperature >> 1)*100) - 25 + ((count_per_c + count_remain) * 100) / count_per_c)
if (temperature.HighByte < $FF) and (temperature.LowByte <> 0) then
TempNeg = "+"
temperature = (((temperature >> 1)*100) - 25 + ((count_per_c - count_remain) * 100) / count_per_c)
else
'************************************************
temperature=$0000 ' THIS IS ONLY NEED TO DEFINE !!!
'************************************************
endif
endif
serout2 GPIO.0,16468, ["Temperature: ", TempNeg, DEC (temperature / 100),".", DEC2 temperature, "C ",13,10]
'return
goto Main
end
Thanks for your help,
Bookmarks