-
-
Neuer Benutzer
Öfters hier
Hallo Windt H.J. ,
thank you, the program works like mine. I only must change a few things.
I test it with ATMEGA32.
Do you have a version, with shows the temperature more exactly?
(not only 0,5 degrees steps)
Here the source:
'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.0 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 9 bit Temperature'
'-55°C to +125°C in 0.5°C increments and display the data on a terminal program as T = xxx,x°C.'
'The temperature is read as -550 to 1250, the last digit is actually the digit behind the comma,'
'example 1: temp_c = -15 is actually -1,5°C'
'example 2: temp_c = 250 is actually 25,0°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 *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' baud rate
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 I2c_byte As Byte
Dim Loops1 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 = 800
'************************************************* ************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature
Temp1 = Temp_c / 10 'calculate hundreds tens ones from temp_c'
Temp1 = Abs(temp1)
Temp2 = Temp_c / 10 'calculate 1/10th from temp_c'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)
Print "T = "; 'display T = '
If Temp_c < 0 Then Print "-"; 'display "-" if temp_c < 0'
Print Temp1 ; "," ; Temp2 ; "°C" 'display temperature as xxx,x°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 I2c_byte , Ack
If I2c_byte > 127 Then Temp_c = &HFF00 + I2c_byte Else Temp_c = I2c_byte
Temp_c = Temp_c * 10
I2crbyte I2c_byte , Nack
Temp1 = I2c_byte And 128
If Temp1 = 128 Then Temp_c = Temp_c + 5
I2cstop
Next
Return
'************************************************* ************************'
'********************************* DATA **********************************'
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
-
Foren-Regeln
Lesezeichen