// Unicorn 1-Wire test
Device = 18F4550
Clock = 48
Config
PLLDIV = 5,
CPUDIV = OSC1_PLL2,
USBDIV = 2,
FOSC = HSPLL_HS,
VREGEN = OFF
// tell the LCD module where it's connected
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTE.0
#option LCD_RW = PORTE.1
#option LCD_EN = PORTE.2
Include "ow.bas"
Include "convert.bas"
Include "LCD.bas"
// working variables...
Dim Temperature As Word
Dim i As Byte
Dim TempString As String
// program start...
ADCON1 = $0F //All digital
CMCON = $07 //No comparators
High(PORTA.2) //power DS18S20
OW.SetPin(PORTA.3) //One Wire is on A3 - needs pullup
LCD.Cls
If(Reset)Then //returns true if device found
WriteByte(owSkipROM) //Skip ROM
WriteByte($44) //Convert
WaitForHigh() //Wait for conversion to complete
Reset()
WriteByte(owSkipROM) //Skip Rom
WriteByte($be) //Read Scratch Pad
Temperature=ReadByte()
Temperature=Temperature+ReadByte()*256
TempString = DecToStr(Temperature*5) // get temperature * 10
//this is a bodge to display temperature with one decimal place
LCD.WriteAt(1,1,"Temp=",TempString(0),TempString(1),".",TempString(2)," Deg C")
//to just display it normal use this next line
// LCD.WriteAt(1,1,"Temp = ",dectostr(Temperature/2)," Deg C")
Reset()
WriteByte(owReadROM) //read rom
For i=0 To 7
LCD.WriteAt(2,(7-i)*2,HexToStr(ReadByte,2))
Next
Else
LCD.WriteAt(1,1,"No Device Found!")
EndIf
End