gramo
New Member
Yet another conversion complete, this one was rather simple as its rather similar to one of the samples that come with SF. This time its for the DS18B20, a Dallas One Wire thermometer.
There are 3 Dallas digital temperature sensors, so be sure to get the correct one. There is the 1820, 18S20 and 18B20. The 18S20 is the successor to the 1820, and does not drift over time. The 18B20 further enhanced, and offers faster conversions. Be aware that the 1820 and 18S20 will not function correctly with this 18B20 example.
**broken link removed**
**broken link removed**
Be sure to attach the 4.7K pull-up resistor to the databus, this is a requirement of the Dallas 1-Wire system. Most of the popular One Wire devices have their own libraries within Swordfish, I'm using the DS18B20 library to make this as simple as possible. Note that Swordfish also has an extensive One Wire library should you want to create your own custom interfacing module.
There are 3 Dallas digital temperature sensors, so be sure to get the correct one. There is the 1820, 18S20 and 18B20. The 18S20 is the successor to the 1820, and does not drift over time. The 18B20 further enhanced, and offers faster conversions. Be aware that the 1820 and 18S20 will not function correctly with this 18B20 example.
**broken link removed**
**broken link removed**
Code:
Device = 18F452
Clock = 20
// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"
// working variables...
Dim
TempA As ShortInt,
TempB As Word
// program start...
SetBaudrate(br19200)
SetPin(PORTC.0)
// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...
If DS18B20.Find Then
While true
Convert
GetTemp(TempA, TempB)
USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
DelayMS(1000)
Wend
Else
USART.Write("No device found", 13, 10)
EndIf
Be sure to attach the 4.7K pull-up resistor to the databus, this is a requirement of the Dallas 1-Wire system. Most of the popular One Wire devices have their own libraries within Swordfish, I'm using the DS18B20 library to make this as simple as possible. Note that Swordfish also has an extensive One Wire library should you want to create your own custom interfacing module.