Hello peter02,

Zitat von
peter02
Ich habe auch einen Fehler in Deiner Korrektur gefunden. Temp_1 gibt es nicht, es muß Temp1 heißen. Aber jetzt klappt wieder alles.
I’m glad you mentioned this!!
This is also wrong, it should be "Temp_c", oops, my fault.
I also found one more error in your modification and corrected it otherwise -0,0 could be displayed.
Here is the corrected version:
Code:
'********************************* PORTS *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' 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
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 Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Config Portb = Output
Config Lcdbus = 4
'*************************************************************************'
'******************************* 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 Temp_c As Integer
'*************************************************************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = 144
Const Ds1621_i2c_r_address = 145
'*************************************************************************'
'********************************* SETUP *********************************'
Config I2cdelay = 80
'*************************************************************************'
'******************************** PROGRAM ********************************'
Cls
Cursor Off Noblink 'hide cursor
Temp_c_loop:
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)
Locate 1 , 1
If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative'
Lcd Temp1 ; "." ; Temp2 ; " C Wohnraum " 'print xxx.x C Wohnraum'
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
Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
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
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
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop
Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop
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
'*************************************************************************'
Success and greetings,
Drifter2006
Lesezeichen