Measuring Temperature using an Analog TMP04 /center>


' Program TMP04.BAS
'
' Illustrates how to measure temperature using TMP04 temperature to 
' frequency converter.  For a data sheet for the TMP04, see 
' http://www.analog.com.
'
' Uses PulseIn to measure high and low times.  Calculates temperature
'
'    T_c = 235.0 - (400 * T_hi/T_lo)
'
' Compile with SerialPort.Bas.
'
' Copyright, Peter H. Anderson, Baltimore, Sept, 99

Public Const P26 as byte = 26	' TMP04 input

Sub Main() 

   Dim T_c as Single
   Dim T_f as Single

   Call OpenSerialPort(2, 9600)		
       
   Do	' continually loop

     Call MeasTemp(T_c)	' measure the temperature in degrees C
     T_f = 1.8 * T_c + 32.0
     Call PutS(T_c)	' display T_c
     Call PutByte(32)	' space
     Call PutS(T_f)	' T_f
     Call NewLine()
     Call Sleep(1.0)
   Loop
End Sub

Sub MeasTemp(ByRef T_c as Single)
   
   Dim T_hi as Single
   Dim T_lo as Single
   
   Call PulseIn(P26, 1, T_hi)	' measure the high time
   Call PulseIn(P26, 0, T_lo)	' low time

   T_c = 235.0 - (400.0 * T_hi/T_lo)
End Sub