Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
include "OW.bas"
Include "USART.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) //Read 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()*256)/2
USART.Write(" Temperature = ",DecToStr(Temperature),"C.",13,10)
else
USART.Write("No device found", 13, 10)
endif
DelayMS (100)
wend
End