After playing around with Bills Junebug demo, I thought I'd have a go at getting a DS1820 working on the Unicorn with an LCD.
It worked almost straight away and I would put that down to Swordfish basic. I had not really played with it but, now I have, it is amazingly good.
Anyway, here's the code,
And this is what it displays and how the DS is wired. The DS is in the bottom three holes of the user connector with a 4k7 resistor from RA3 to 5V. The second row is the DS's ROM id.
**broken link removed**
Mike.
It worked almost straight away and I would put that down to Swordfish basic. I had not really played with it but, now I have, it is amazingly good.
Anyway, here's the code,
Code:
// 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
And this is what it displays and how the DS is wired. The DS is in the bottom three holes of the user connector with a 4k7 resistor from RA3 to 5V. The second row is the DS's ROM id.
**broken link removed**
Mike.
Last edited: