This may help others who are working with a T-String or multiple DS18B20's all on the same 2 lines and in parasitic mode
Code: Select all
// if device and clock are omitted, then the compiler defaults to
// 18F452 @ 20MHz - they are just used here for clarity...
Device = 18F452
Clock = 10
//DEVICE FUSE CONFIG
'Config
' OSC = HS, // HS Oscillator
' FCMEN = OFF, // Failsafe Clock Monitor Disabled
' IESO = OFF, // Int/Ext Oscillator Switch Over Disabled
' PWRT = OFF, // Power Up Timer Disabled
' BOREN = OFF, // Brownout Reset Disabled
' WDT = OFF, // Watchdog Timer Disabled
' MCLRE = On, // MCLR Enabled
' WDTPS = 256, // 15000 x 4mS = 60 seconds
' LVP = OFF, // Low_Voltage Programming
' PBADEN = OFF // PORTB Digital
// import modules...
Include "convert.bas"
Include "string.bas"
Include "SUART.bas"
Include "DS2431.bas"
Include "DS18B20.bas"
Include "OW.bas"
Include "math.bas"
Dim DataPin As PORTC.0
// working variables...
Dim DeviceCount As Byte
Dim TMEM(144) As Byte
Dim TempA As ShortInt
Dim TempB As Word
Dim TempC As Float
Dim TempF As Float
Dim IDX_MAIN As Byte
// display ROM ID for search item...
Sub DisplayRomID()
Const ArrayA(8) As Byte = (7,6,5,4,3,2,1,0)
Dim IDX As Byte
UART.Write("RomID ($")
For IDX = 0 To 7
UART.Write(HexToStr(RomID(ArrayA(IDX)),2),32)
Next
UART.Write(")",13,10)
End Sub
Sub CheckAvailable()
If DS18B20.Available() = TRUE Then
UART.Write(" ID Matches",13,10)
Else
UART.Write(" ID Doesn't Match",13,10)
EndIf
End Sub
Sub DisplayMem()
Dim IDX_A As Byte
Dim IDX_B As Byte
For IDX_A = 0 To 17
UART.Write("Memory ($")
For IDX_B = 0 To 7
UART.Write(HexToStr(TMEM(IDX_B+(IDX_A * 8) - 1),2),32)
Next
UART.Write(")",13,10)
Next
End Sub
Sub DisplayTemp()
Dim BUFF1 As Byte
Dim BUFF2 As LongWord
BUFF1 = Length(DecToStr(TempB))
BUFF2 = Pow(10,BUFF1)
TempC = TempB / (BUFF2 + 0.0)
TempC = TempA + TempC
TempF = (TempC * 9 / 5) + 32
UART.Write("TEMP",DecToStr(IDX_MAIN),32,DecToStr(TempA),46,DecToStr(TempB),32,FloatToStr(TempC),32,FloatToStr(TempF),32,13,10)
End Sub
Sub LoadSensorROM()
DS2431.Find() //Find the EEPROM
DS2431.ReadMemory(TMEM) //Read 144 bytes from EPROM and Load into TMEM
End Sub
Sub LoadRomID(pSENSOR As Byte) //Spec Sensor to Talk To
Dim OFFSET As Byte
Dim BUFF(8) As Byte
OFFSET = (pSENSOR + 1) * 8
BUFF(7) = TMEM(OFFSET)
BUFF(6) = TMEM(OFFSET + 1)
BUFF(5) = TMEM(OFFSET + 2)
BUFF(4) = TMEM(OFFSET + 3)
BUFF(3) = TMEM(OFFSET + 4)
BUFF(2) = TMEM(OFFSET + 5)
BUFF(1) = TMEM(OFFSET + 6)
BUFF(0) = $28
RomID = BUFF
End Sub
'Configure Software UART for Debugging
UART.SetTX(PORTB.7)
UART.SetRX(PORTB.6)
UART.SetBaudrate(sbr9600)
UART.SetMode(umTrue)
// program start...
High(PORTC.0)
Low(PORTC.1)
DelayMS(2000)
SetPin(DataPin)
While True
DeviceCount = Search(owSearchROM)', OnFind)
UART.Write(DecToStr(DeviceCount), " device(s) found", 13, 10)
If DS2431.Find() = TRUE Then
DisplayRomID()
UART.Write(")",13,10)
DS2431.ReadMemory(TMEM) //Read 144 bytes from EPROM and Load into TMEM
Else
UART.Write("EEPROM Not Found",13,10)
EndIf
DisplayMem()
UART.Write(13,10)
For IDX_MAIN = 0 To 0
LoadRomID(IDX_MAIN)
DisplayRomID()
CheckAvailable()
DS18B20.Convert()
High(PORTC.1)
DelayMS(750)
Low(PORTC.1)
DS18B20.GetTemp(TempA, TempB)
DisplayTemp()
Next
UART.Write(13,10)
Wend