| CODE |
' *************************************************************************** ' * ' * Title : Temperature indicator ' * Version : 1.0 ' * Last Updated : 15.03.2003 ' * Target : At90s2313 ' * Author : r.meurs@planet.nl ' * Program code : BASCOM AVR ' * Hardware req. : Temperatue indicator board ' * ' * ' * Description ' * This application reads the temperature from an DS1621 temp. sensor ' * One of three LED's is on when the temperature is within a certain range. ' * ' **************************************************************************** Dim Tempmsb As Byte Dim Templsb As Byte Dim L_on As Byte Dim L_off As Byte Dim Tl As Byte Dim Th As Byte Dim Confg As Byte Dim Count As Byte Dim Slope As Byte Declare Sub Get_temp Declare Sub Write_th Declare Sub Write_tl Config Portb = Output Portb = 255 Config Sda = Portd.0 Config Scl = Portd.1 Cls Cursor Off Goto Main Sub Write_th I2cstart I2cwbyte &H90 I2cwbyte &HA1 I2cwbyte L_on I2cstop End Sub Write_th '-------------- Sub Write_tl I2cstart I2cwbyte &H90 I2cwbyte &HA2 I2cwbyte L_off I2cstop End Sub Write_tl '-------------- 'read TH I2cstart I2cwbyte &H90 I2cwbyte &HA1 I2cstop I2cstart I2cwbyte &H91 I2crbyte Th , Nack I2cstop '-------------- 'read TL I2cstart I2cwbyte &H90 I2cwbyte &HA2 I2cstop I2cstart I2cwbyte &H91 I2crbyte Tl , Nack I2cstop '-------------- 'read config I2cstart I2cwbyte &H90 I2cwbyte &HAC I2cstop I2cstart I2cwbyte &H91 I2crbyte Confg , Nack I2cstop '-------------- 'read counter I2cstart I2cwbyte &H90 I2cwbyte &HA8 I2cstop I2cstart I2cwbyte &H91 I2crbyte Count , Nack I2cstop '-------------- 'read slope I2cstart I2cwbyte &H90 I2cwbyte &HA9 I2cstop I2cstart I2cwbyte &H91 I2crbyte Slope , Nack I2cstop '-------------- Sub Get_temp: 'start convert I2cstart I2cwbyte &H90 I2cwbyte &HEE I2cstop '------------- 'read temperature I2cstart I2cwbyte &H90 I2cwbyte &HAA I2cstop I2cstart I2cwbyte &H91 I2crbyte Tempmsb , Ack I2crbyte Templsb , Nack I2cstop 'read config I2cstart I2cwbyte &H90 I2cwbyte &HAC I2cstop I2cstart I2cwbyte &H91 I2crbyte Confg , Nack I2cstop End Sub Get_temp '-------------- Main: L_on = 25 'if Temp > 25 the load will be switched on L_off = 20 'if Temp < 20 the load will be switched off Gosub Write_th Gosub Write_tl Loop: Wait 1 Gosub Get_temp Select Case Tempmsb Case Is < 21 : Portb = &B00000001 'if Temp <21 then the yellow LED is on Case 21 To 25 : Portb = &B00000010 'if Temp is between 21 and 25 then the green LED is on Case Is > 25 : Portb = &B00000100 'if Temp >25 then the red LED is on End Select Goto Loop |