Das ist der Code, ist für die Abfrage des Temp Sens auf i2c. Ist aus nem anderen Thread. Habe gelesen das hat was mit der mcs lib zu tun. Könnte die jemand vllt uppen?Code:$regfile = "m168def.dat" $regfile = "M32def.dat" ' chip $crystal = 16000000 ' frequenz $baud = 19200 ' baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space $lib "I2C_TWI.LBX" Config Scl = Portc.0 ' we need to provide the SCL pin name Config Sda = Portc.1 ' we need to provide the SDA pin name Config Twi = 100000 ' wanted clock frequency 'Twbr = 12 'bit rate register 'will set TWBR and TWSR 'Twsr = 0 'pre scaler bits Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.5 , Rs = Portb.7 ' Pinbelegung "LCD-Port)" Config Lcd = 20 * 4a , Chipset = Ks077 ' LCD 204 DIP 20x4 'Config Lcd = 16 * 2 , Chipset = Dogm163v5 , Contrast = &H702 ' EA DOGM162W-A Config Portb = Output Config Lcdbus = 4 Config Portc.6 = Output 'Toggle bei jeder Messung die LED C.6 Config Portc.7 = Output 'Temperatur unter 0 °C LED C.7 '*************************************************************************' '******************************* VARIABLES *******************************' Dim ___lcdno As Bit Dim I2c_byte As Byte Dim Loops1 As Byte Dim Count As Byte Dim Slope As Byte Dim Temp1 As Integer Dim Temp2 As Integer Dim Temp3 As Integer Dim Temp_cor As Integer Dim Temp3_s As String * 16 Dim Temp_c As Integer Dim Ds1621_i2c_address As Integer Dim Ds1621_i2c_r_address As Integer '*************************************************************************' Config I2cdelay = 800 Initlcd Deflcdchar 1 , 3 , 3 , 32 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7) Cls Cursor Off Noblink 'hide cursor '*************************************************************************' '******************************** PROGRAM ********************************' '***** Innen Temp_c_loop: Ds1621_i2c_address = 144 Ds1621_i2c_r_address = 145 Temp_cor = 0 Gosub Get_ds1621_temperature Print "oben" Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 ; " " ; "Temp_c" ; " " ; Temp_c 'Test auf das Terminal Print " " Temp1 = Temp_c / 10 'get hundreds tens ones xxx,' Temp1 = Abs(temp1) Temp2 = Temp_c / 10 'get 1/10 ,x' Temp2 = Temp2 * 10 Temp2 = Temp_c - Temp2 Temp2 = Abs(temp2) Temp3 = Temp1 * 10 Temp3 = Temp3 + Temp2 Temp3 = Temp3 + Temp_cor ' fuer den Korrekturfaktor Temp3_s = Str(temp3) ' der Formatbefehl erfordert einen String Toggle Portc.6 'Toggle bei jeder Messung Locate 1 , 1 If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative' Locate 1 , 2 Lcd Format(temp3_s , "00.0") ; Chr(1) ; "C Innen" 'print xxx.x C Wohnraum' Print "unten" Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 ; " " ; "Temp_c" ; " " ; Temp_c 'Test auf das Terminal Print " " Wait 1 'Goto Temp_c_loop ' nur bei einer Temperatur '***** Aussen 'Temp_c_loop: Ds1621_i2c_address = 146 Ds1621_i2c_r_address = 147 Temp_cor = 0 Gosub Get_ds1621_temperature Temp1 = Temp_c / 10 'get hundreds tens ones xxx,' Temp1 = Abs(temp1) Temp2 = Temp_c / 10 'get 1/10 ,x' Temp2 = Temp2 * 10 Temp2 = Temp_c - Temp2 Temp2 = Abs(temp2) Temp3 = Temp1 * 10 Temp3 = Temp3 + Temp2 ' fuer den Korrekturfaktor Temp3_s = Str(temp3) ' der Formatbefehl erfordert einen String Locate 2 , 1 If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative' Locate 2 , 2 If Temp1 < 10 Then Lcd " " ; Format(temp3_s , "0.0") ; Chr(1) ; "C Aussen" ' unter 10 C print x.x C Aussen' Else ' über 10 C print xx.x C Aussen' Lcd Format(temp3_s , "00.0") ; Chr(1) ; "C Aussen" End If 'Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 'Test auf das Terminal Wait 1 Goto Temp_c_loop '*************************************************************************' '****************************** SUBROUTINES ******************************' Get_ds1621_temperature: For Loops1 = 1 To 2 Ds1621_start_convert: I2cstart I2cwbyte Ds1621_i2c_address I2cwbyte &HEE I2cstop Waitms 25 Ds1621_check_conversion_done: I2cstart I2cwbyte Ds1621_i2c_address I2cwbyte &HAC I2cstop Waitms 25 I2cstart I2cwbyte Ds1621_i2c_r_address I2crbyte I2c_byte , Nack I2cstop Waitms 25 Temp1 = I2c_byte And 1 Temp2 = I2c_byte And 128 If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done Ds1621_read_temp: I2cstart I2cwbyte Ds1621_i2c_address I2cwbyte &HAA I2cstop Waitms 25 I2cstart I2cwbyte Ds1621_i2c_r_address I2crbyte Temp_c , Nack If Temp_c > 127 Then Temp_c = Temp_c + &HFF00 Temp_c = Temp_c * 100 Ds1621_read_count: I2cstart I2cwbyte Ds1621_i2c_address I2cwbyte &HA8 I2cstop Waitms 25 I2cstart I2cwbyte Ds1621_i2c_r_address I2crbyte Count , Nack I2cstop Waitms 25 Ds1621_read_slope: I2cstart I2cwbyte Ds1621_i2c_address I2cwbyte &HA9 I2cstop Waitms 25 I2cstart I2cwbyte Ds1621_i2c_r_address I2crbyte Slope , Nack I2cstop Waitms 25 Temp1 = Count * 100 Temp2 = Slope * 100 Temp2 = Temp2 - Temp1 Temp1 = Temp2 / Slope Temp_c = Temp_c - 25 Temp_c = Temp_c + Temp1 Temp_c = Temp_c / 10 'get rid of last digit xxxxx becomes xxxx' I2cstop Next Return
MfG
Placa







Zitieren

Lesezeichen