Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: 2 x DS1621 v1.4 Kategorie: Programmierung Basic (von Windt H.J. - 8.02.2006 19:13)
 Als Antwort auf Re: 2 x DS1621 v1.3 von Hans - 8.02.2006 17:55
Hello,
Thank you very much for warning me about this!
The problem was not with the variables temp_in or temp_out but with the way they are displayed.
I guess I missed this while testing my example.

Here is the corrected version, v1.4
Let me know how it works out.
Greetings,
H.J. Windt

'* 2xDS1621 v1.4*'
'**************** I/O PORTS ****************'
define lcd_backlight_off port[16]
'*******************************************'
'**************** VARIABLES ****************'
define configuration byte[1]
define iic_nack bit[7]
define ds1621_in_error bit[9]
define ds1621_out_error bit[10]
define iic_nack_count byte[3]
define iic_byte byte[4]
define ds1621_status byte[5]
define loop byte[6]
define temp_in word[4]
define temp_out word[5]
'*******************************************'
'**************** CONSTANTS ****************'
define ds1621_in_iic_address &h90
define ds1621_out_iic_address &h92
'*******************************************'
'****************** SETUP ******************'
put 0:print"#ON_LCD#";:print"#INIT#";:print"#CLR#";:lcd_backlight_off = 0:print"#OFF#";
'*******************************************'
'***************** PROGRAM *****************'
#start
gosub get_ds1621_temperature

print"#ON_LCD#";

print"#L101#";:print"T in = ";
if temp_in < 0 then print"-";
print abs(temp_in/10);",";abs(temp_in-temp_in/10*10);:put&hdf:print"C  ";
print"#L108#";:if ds1621_in_error <> 0 then print"IIC Error   ";

print"#L201#";:print"Tout = ";
if temp_out < 0 then print"-";
print abs(temp_out/10);",";abs(temp_out-temp_out/10*10);:put&hdf:print"C  ";
print"#L208#";:if ds1621_out_error <> 0 then print"IIC Error   ";

print"#OFF#";
goto start
'*******************************************'
'*************** SUBROUTINES ***************'
#get_ds1621_temperature
ds1621_in_error = 0
ds1621_out_error = 0
for loop = 1 to 2
#ds1621_start_convert
print"#ON_IIC#";
print"#START#";
gosub ds1621_write_address
put &hee
print"#STOP#";
print"#OFF#";
gosub check_iic_nack
if iic_nack_count > 6 then goto no_ack_from_ds1621
if iic_nack then goto ds1621_start_convert
#ds1621_check_conversion_done
print"#ON_IIC#";
print"#START#";
gosub ds1621_write_address
put &hac
print"#STOP#";
print"#OFF#";
gosub check_iic_nack
if iic_nack then goto ds1621_pass_check_conversion_done
print"#ON_IIC#";
print"#START#";
gosub ds1621_read_address
get ds1621_status
print"#STOP#";
print"#OFF#";
gosub check_iic_nack
#ds1621_pass_check_conversion_done
if iic_nack_count > 9 then goto no_ack_from_ds1621
if iic_nack then goto ds1621_check_conversion_done
if (ds1621_status and 1) = 1 then if (ds1621_status and 128) = 0 then goto ds1621_check_conversion_done
#ds1621_read_temp
print"#ON_IIC#";
print"#START#";
gosub ds1621_write_address
put &haa
print"#STOP#";
print"#OFF#";
gosub check_iic_nack
if iic_nack then goto pass_ds1621_read_temp
print"#ON_IIC#";
print"#START#";
gosub ds1621_read_address
get iic_byte
if loop = 1 then if iic_byte > 127 then temp_in = (&hff00 + iic_byte) * 10 else temp_in = iic_byte * 10
if loop = 2 then if iic_byte > 127 then temp_out = (&hff00 + iic_byte) * 10 else temp_out = iic_byte * 10
get iic_byte
if loop = 1 then if (iic_byte and 128) = 128 then temp_in = temp_in + 5
if loop = 2 then if (iic_byte and 128) = 128 then temp_out = temp_out + 5
print"#STOP#";
print"#OFF#";
gosub check_iic_nack
#pass_ds1621_read_temp
if iic_nack_count > 9 then goto no_ack_from_ds1621
if iic_nack then goto ds1621_read_temp
if temp_in = -600 then goto ds1621_start_convert
if temp_out = -600 then goto ds1621_start_convert
#pass_get_ds1621_temperature
next
return

#ds1621_write_address
if loop = 1 then put ds1621_in_iic_address
if loop = 2 then put ds1621_out_iic_address
return

#ds1621_read_address
if loop = 1 then put ds1621_in_iic_address + 1
if loop = 2 then put ds1621_out_iic_address + 1
return

#check_iic_nack
print"#ON_CONFIG#";
get configuration
if not iic_nack then goto pass_iic_nack_clear
iic_nack = 0
put configuration
iic_nack = 1
iic_nack_count = iic_nack_count + 1
print"#OFF#";
return
#pass_iic_nack_clear
iic_nack_count = 0
print"#OFF#";
return
'*******************************************'
'******* INITIALIZATION SUBROUTINES ********'

'*******************************************'
'****************** DATA *******************'

'*******************************************'
'************* ERROR MESSAGES **************'
#no_ack_from_ds1621
beep 1,1,1:beep 10,1,1:beep 1,1,1:beep 10,1,1
if loop = 1 then ds1621_in_error = 1
if loop = 2 then ds1621_out_error = 1
goto pass_get_ds1621_temperature
'*******************************************'

 Antwort schreiben

Bisherige Antworten:

Re: 2 x DS1621 v1.4 (von Hans - 8.02.2006 20:00)