'***************************************************************************** '* '* Title : TCN75 digital thermometer '* Version : 1.0 '* program code : BASCOM AVR basic '* Last updated : 2002 04 20 '* Target : AT90S2313 '* Hardware requirements: STK500, LCD interface board, thermometer board with DS1621. '* '* DESCRIPTION '* This program shows the temperature on the LCD interface, the temperature is measured '* with the TCN75 which has an I2C interface. '***************************************************************************** Dim Tempmsb As Byte Dim Templsb As Byte Dim Th As Byte Dim Tl As Byte Dim Confg As Byte Dim Count As Byte Dim Slope As Byte Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.6 , Rs = Portb.7 Config Lcd = 16 * 2 $crystal = 10000000 $baud = 9600 Deflcdchar 0 , 14 , 17 , 17 , 17 , 14 , 32 , 32 , 32 'degree Deflcdchar 1 , 4 , 14 , 31 , 32 , 32 , 32 , 32 , 32 'up Deflcdchar 2 , 32 , 32 , 32 , 32 , 32 , 31 , 14 , 4 'down Deflcdchar 3 , 32 , 32 , 32 , 31 , 31 , 32 , 32 , 32 'equal Config Sda = Portd.3 Config Scl = Portd.2 Cls Cursor Off Goto Loop 'write TH I2cstart I2cwbyte &H90 I2cwbyte &HA1 I2cwbyte 25 I2cstop '-------------- 'write TL I2cstart I2cwbyte &H90 I2cwbyte &HA2 I2cwbyte 20 I2cstop '-------------- '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 '-------------- Goto Loop 'read counter Readcnt: I2cstart I2cwbyte &H90 I2cwbyte &HA8 I2cstop I2cstart I2cwbyte &H91 I2crbyte Count , Nack I2cstop Return '-------------- 'read slope Readslp: I2cstart I2cwbyte &H90 I2cwbyte &HA9 I2cstop I2cstart I2cwbyte &H91 I2crbyte Slope , Nack I2cstop Return '-------------- 'read config I2cstart I2cwbyte &H90 I2cwbyte &HAC I2cstop I2cstart I2cwbyte &H91 I2crbyte Confg , Nack I2cstop 'start convert I2cstart I2cwbyte &H90 I2cwbyte &H00 I2cstop '------------- Loop: I2cstart I2cwbyte &H90 I2cwbyte &H01 I2cstop I2cstart I2cwbyte &H90 I2cwbyte &H18 I2cstop 'read temperature I2cstart I2cwbyte &H90 I2cwbyte &H00 I2cstop I2cstart I2cwbyte &H91 I2crbyte Tempmsb , Ack I2crbyte Templsb , Nack I2cstop Wait 1 If Templsb = 128 Then Templsb = 5 Else Templsb = 0 Locate 1 , 1 Lcd "TCN75 Thermometer" Locate 2 , 1 Lcd "**** " ; Tempmsb ; "," ; Templsb ; Chr(0) ; "C" ; " ****" Print Tempmsb ; "," ; Templsb Goto Loop