Const DQ as Byte = 7 Const CLK as Byte = 8 Const RTS as Byte = 9 Const CONFG_REG as Byte = &H0C Const CONFG_DS1620 as Byte = &H02 Const READ_STATUS as Byte = &HAC Const READ_HIGH as Byte = &HA1 Const SET_HIGH as Byte = &H01 Const READ_LOW as Byte = &HA2 Const SET_LOW as Byte = &H02 Const START_CONVERT as Byte = &HEE Const STOP_CONVERT as Byte = &H22 Const READ_TEMP as Byte = &HAA Sub Main() Dim N as Integer Dim Dat(1 To 9) as Byte Call OpenSerialPort(1, 19200) Call RtsLow(RTS) Call ClkHigh(CLK) Call RtsHigh(RTS) Call OutByte_3W(DQ, CONFG_REG) Call OutByte_3W(DQ, CONFG_DS1620) Call RtsLow(RTS) Sleep 2000 Call ClkHigh(CLK) Call RtsHigh(RTS) Call OutByte_3W(DQ, START_CONVERT) Call RtsLow(RTS) Sleep 200 Call ClkHigh(CLK) Call RtsHigh(RTS) Call OutByte_3W(DQ, READ_TEMP) For N = 1 to 9 Call ClkLow(CLK) Dat(N) = InByte_3W(DQ) ' fetch the nine bytes Call ClkHigh(CLK) Next Call RtsLow(RTS) For N = 1 to 9 Call PutHexB(Dat(N)) Call PutByte(Asc(" ")) Next Call NewLine() Call ClkHigh(CLK) Call RtsHigh(RTS) Call OutByte_3W(DQ, STOP_CONVERT) Call RtsLow(RTS) End Sub Function InByte_3W(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_3W = IByte End Function Sub OutByte_3W(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 PutPin(Pin, 1) Else Call PutPin(Pin, 0) End If OByte = OByte \ 2 Next End Sub Sub RtsHigh(ByVal Pin as Byte) Call PutPin(Pin, 1) End Sub Sub RtsLow(ByVal Pin as Byte) Call PutPin(Pin, 0) End Sub Sub ClkHigh(ByVal Pin as Byte) Call PutPin(Pin, 1) End Sub Sub ClkLow(ByVal Pin as Byte) Call PutPin(Pin, 0) 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