
Zitat von
peter02
Do you have a version, with shows the temperature more exactly?
(not only 0,5 degrees steps)
Hello,
I have had success writing new software (CCBasic C-Control) that reads and shows the temperature in smaller increments. \
/
I translated it into Bascom 8051 but I’m not able to compile and test it (demo version of Bascom 8051).
With A few modifications it should work on an AVR.
Let me know how it works out.
Greetings,
Windt H.J.
Code:
'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.1 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 8 bit Temperature, Counter And Slope and'
'display the data on a terminal as T = xxx , xx°C'
'The temperature is read as -5500 to 12500, the last 2 digits are actually the digits behind the comma,'
'example 1: temp_c = -150 is actually -1,50°C'
'example 2: temp_c = 2500 is actually 25,00°C.
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
Config Sda = P1.0
Config Scl = P1.1
'*************************************************************************'
'******************************* VARIABLES *******************************'
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 = &H0
Const Ds1621_i2c_r_address = &H1
'*************************************************************************'
'********************************* SETUP *********************************'
Config I2cdelay = 800
'*************************************************************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature
Temp1 = Temp_c / 100
Temp1 = Abs(temp1)
Temp2 = Temp_c / 100
Temp2 = Temp2 * 100
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)
Print "T = ";
If Temp_c < 0 Then Print "-";
Print Temp1 ; "," ;
If Temp2 < 10 Then Print "0";
Print Temp2 ; "°C"
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
I2cstop
Next
Return
'*************************************************************************'
'********************************* DATA **********************************'
'*************************************************************************'
Lesezeichen