Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "OW.bas"
Include "USART.bas"
Include "DS18B20.bas"
Include "CONVERT.bas"
Dim Temperature As Word
Dim i As Byte
OSCCON = $72 // select 8MHz internal clock
ADCON1 = $7f //all digital
TRISA.3=0 //A3 output
PORTA.3=1 //and high
SetBaudrate(br9600)
OW.SetPin(PORTA.4)
While true
If OW.Reset Then
OW.WriteByte(owReadROM) //Skip ROM
USART.Write("Rom = ")
For i = 0 To 7
USART.Write(HexToStr(OW.ReadByte()))
Next
OW.Reset
OW.WriteByte(owSkipROM) //Skip ROM
OW.WriteByte($44) //Convert
OW.Reset
OW.WaitForHigh //wait for convert to finish
OW.Reset
OW.WriteByte(owSkipROM) //Skip Rom
OW.WriteByte($be) //Read Scratch Pad
Temperature=OW.ReadByte()
Temperature=(Temperature+OW.ReadByte()*128)
changing this formula
USART.Write(" Temperature = ",DecToStr(Temperature/4))
If (Temperature And 1) = 1 Then
USART.Write(".5")
EndIf
USART.Write("C",13,10)
Else
USART.Write("No device found", 13, 10)
EndIf
DelayMS (100)
Wend
End