Professional Documents
Culture Documents
DATA 46, 224, 20 ' Temp MSB, TEMP LSB, Hysteresis DIV 10
Pause 500
LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
Pause 250
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $4E, $FF, $FF, $7F] '
Init Sensor 1
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $48]
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $B8]
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $BE]
Pause 1000
OWIn DQ, 0, [Temperature1.Byte0, Temperature2.Byte1]
LcdOut $FE, $80, "Senzor1 INIT OK"
Pause 500
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $4E, $FF, $FF, $7F] '
Init Sensor 2
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $48]
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $B8]
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $BE]
Pause 1000
OWIn DQ, 0, [Temperature2.Byte0, Temperature2.Byte1]
LcdOut $FE, $C0, "Senzor2 INIT OK"
Pause 1000
MainLoop:
If PORTB.0=0 then ' Mode switch pressed
Pause 50 ' Debounce
LcdOut $FE, 1
LcdOut $FE, $8F, "*" ' Show that command is accepted
If PORTB.0=0 then MainLoop ' Wait until button is released
Mode=Mode+1 ' Increment mode
If Mode=2 then ' Save Target Temperature (Mode1 -> Mode2)
Write 0, TargetTemp / 256 ' TargetTemp MSB
Write 1, TargetTemp MOD 256 ' TargetTemp LSB
EndIf
If Mode > 2 Then ' Save Hysteresis (Mode 2 -> Mode 0)
Mode=0 ' Only 0, 1, 2 are valid
Write 2, Hyst / 10 ' Divide Hyst value to fit in Byte
EndIf
EndIf
If Mode =1 then
LcdOut $FE, $80, "SET TEMPERATURE " ' Show function
V=TargetTemp ' TargetTemp in V
Gosub SelectSign ' Select +/blank/-
Gosub DTemp ' Display Target Temperature
If (PORTB.1=0) Or (PORTB.2=0) then ' Up or Down button pushed
If PORTB.2=0 then ' Down button
If TargetTemp > 7500 then ' Not lower than -25 C. (10000-MinTemp *
100)
TargetTemp=TargetTemp-25 ' Decrease temperuture with 0.25 C.
EndIf
EndIf
If PORTB.1=0 then ' Up button
If TargetTemp < 17500 then ' Not higher than 75 C. (10000+MaxTemp *
100)
TargetTemp=TargetTemp+25 ' Increase temperature with 0.25 C.
EndIf
EndIf
GoSub SetTargetTemp ' Display TargetTemp and delay 0.25 Sec.
EndIf
EndIf
'==================================================================================
=================
Main :
Part1:
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $44] ' Start temp.
conversion Sensor1
WaitLoop:
While not DQ
Wend
OWOut DQ, 1, [$55, $28, $DD, $06, $49, $1, $0, $0, $D4, $BE]
Pause 500
OWIn DQ, 0, [Temperature1.Byte0, Temperature1.Byte1]
If Temperature1.15 then
Temperature1= ~Temperature1 +1
Twist = 1
Endif
'==================================================================================
=================
Part2 :
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $44] ' Start temp.
conversion Sensor2
WaitLoop2:
While not DQ
Wend
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $BE]
Pause 500
OWIn DQ, 0, [Temperature2.Byte0, Temperature2.Byte1]
If Temperature2.15 then
Temperature2= ~Temperature2 +1
Twist2 = 1
Endif
' SUBROUTINES:
'==================================================================================
=================
SelectSign:
If v = 10000 then ' Temperature = 0 C.
Sign=" " ' No sign
Else
If v < 10000 then ' <> 0
Sign="-" ' Temperature below 0 C.
Else
Sign="+" ' Temperature above 0 C.
EndIf
EndIf
Return
'==================================================================================
=================
DisplayTemp:
If V >= 10000 then ' Above 0 C.
Temperature1=V-10000
Else
Temperature1=10000-V ' Below 0 C.
EndIf
LcdOut $FE, $80, "INT : ", Sign," ", DEC (Temperature1 / 100), ".", DEC2
Temperature1, " ",223,"C "
LcdOut $FE, $C0, "EXT : ", Sign," ", DEC (Temperature2 / 100), ".", DEC2
Temperature2, " ",223,"C "
Return
'==================================================================================
=================
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DTemp
Pause 250
Return
'==================================================================================
=================
DTemp :
If V >= 10000 then ' Above 0 C.
Temperature1=V-10000
Else
Temperature1=10000-V ' Below 0 C.
EndIf
LcdOut $FE, $C0, Sign," ", DEC (Temperature1 / 100), ".", DEC2 Temperature1, "
",223,"C "
Return