Interface with Dallas DS2435 Temperature / Histogram IC
' DS2435_2.Bas (BX24)
'
' Illustrates an interface with a Dallas DS2435 Temperature / Histogram IC
' The DS2435 is a member of the Dallas 1-W Family.
'
' Illustrates use temperature histogram feature.
'
' Program sets sample rate to 0.5 minutes, sets the seven temperature boundaries and clears
' the histogram counters.
'
' The program then continually loops and displays the histogram counters about every two
' minutes.
'
'
' BX24 DS2435
' +5
' |
' * 4.7K
' |
' RA.7 (Term 13) ---------------------- DQ (term 2)
' Term 1 - GRD
' Term 3 - +5V
'
' Build project with SerialPort.Bas.
'
' This was developed as a part of a Senior Project performed by Ernest Wells
' at Morgan State University.
'
' copyright, Ernest Wells, Peter H. Anderson, Baltimore, MD, May, '01
Sub Main()
Dim A(1 to 16) as Byte, N as Integer
Dim Count as Integer
Dim TemperatureBounds(1 to 7) as Byte
Call OpenSerialPort(1, 19200)
Call Set2435SampleRate(0) ' every half minute
A(1) = 0
A(2) = 0
A(3) = 0
Call Set2435ElapsedTime(A) ' zero the elapsed time
Call Reset2435Histogram() ' clear histogram counters
TemperatureBounds(1) = 22 ' define temperatures
TemperatureBounds(2) = 24
TemperatureBounds(3) = 26
TemperatureBounds(4) = 28
TemperatureBounds(5) = 30
TemperatureBounds(6) = 32
TemperatureBounds(7) = 34
Call Set2435TemperatureBounds(TemperatureBounds)
Call Init_1W(13) ' start logging
Do
Call Read2435Histogram(A)
Call Init_1W(13) ' continue logging
For N = 1 to 8 ' print the values of the eight counters
Count = CInt(A(2*N)) * 256 + CInt(A(2*N - 1))
Debug.Print CStr(Count); " ";
Next
Debug.Print ' new line
Sleep(120.0) ' two minute delay
Loop
End Sub
Sub Set2435TemperatureBounds(ByRef A() as Byte)
Dim N as Integer
Call Init_1W(13)
Call OutByte_1W(13, &HEF)
Call OutByte_1W(13,&H84)
For N = 1 to 7
Call OutByte_1W(13, A(N))
Next
End Sub
Sub Reset2435Histogram()
Call Init_1W(13)
Call OutByte_1W(13, &HE1)
End Sub
Sub Read2435Histogram(ByRef A() as Byte)
Dim N as Integer
Call Init_1W(13)
Call OutByte_1W(13, &HB2)
Call OutByte_1W(13, &H64)
For N = 1 to 16
A(N) = InByte_1W(13)
Next
End Sub
Sub Set2435SampleRate(ByVal V as Byte)
Call Init_1W(13)
Call OutByte_1W(13, &HEF)
Call OutByte_1W(13,&H8B)
Call OutByte_1W(13,V)
End Sub
Sub Set2435ElapsedTime(ByRef A() as Byte)
Call Init_1W(13)
Call OutByte_1W(13, &HE6)
Call OutByte_1W(13, A(1))
Call OutByte_1W(13, A(2))
Call OutByte_1W(13, A(3))
End Sub
Sub Init_1W(ByVal Pin as Byte) ' bring Pin low for 500 usecs and then back
' high
Dim N as Integer
Call PutPin(Pin, 2) ' be sure DQ is an input
Call PutPin(Pin, 0)
For N = 1 to 3 ' adjust for 500 usec delay
Next
Call PutPin(Pin, 2)
For N = 1 to 3
Next
End Sub
Function InByte_1W(ByVal Pin as Byte) as Byte
Dim N as Integer, IByte as Byte, B as Byte
For N =1 to 8
B = Get1Wire(Pin)
If (B=1) then
IByte = (IByte\2) OR bx10000000
Else
IByte = IByte\2
End If
Next
InByte_1W = IByte
End Function
Sub OutByte_1W(ByVal Pin as Byte, ByVal OByte as Byte)
Dim N as Integer, B as Byte
For N = 1 to 8
B = OByte AND bx00000001
If (B=1) Then
Call Put1Wire(Pin, 1)
Else
Call Put1Wire(Pin, 0)
End If
OByte = OByte \ 2
Next
End Sub
Sub StrongPullUp_1W(ByVal Pin as Byte)
' Provide a hard logic one for 0.5 secs
Call PutPin(Pin, 1)
Call Sleep(0.5)
Call PutPin(Pin, 2)
End Sub
Sub PutHexB(ByVal X as Byte) ' display a byte in hex format
Dim Y as Byte
Y= X \ 16 ' convert high nibble to character
If (Y < 10) then
Y = Y + Asc("0")
Else
Y = Y - 10 + Asc ("A")
End If
Call PutByte(Y)
Y= X And bx00001111 ' same for low nibble
If (Y < 10) then
Y = Y + Asc("0")
Else
Y = Y - 10 + Asc ("A")
End If
Call PutByte(Y)
End Sub