Hteo bi da dodam podesavanje za još jednu temperaturu, i histerezu ali mi nešto ne štima:
Code: Select all
'*****************************************************************************
'* LCD Defines for EasyPic5 & 16F887 *
'*****************************************************************************
clear
ANSEL = %00000000 'All digital
ANSELH = %00000000
OPTION_REG.7 = 1 'Weak pull-ups enabled
DEFINE LCD_DREG PORTB ' I/O port where LCD is connected
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 4 ' Register select pin RA4
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 2 ' Enable pin RA2
DEFINE LCD_BITS 4 ' 4-bit data bus
DEFINE LCD_LINES 2 ' LCD has 2 character lines
DEFINE OSC 4
DEFINE BUTTON_PAUSE 100
'*****************************************************************************
'Pinout for EasyPic5
Re1 Var PORTB.1 'Relej1
Re2 Var PORTB.2 'Relej2
Re3 var PORTA.1 'Relej3
DQ Var PORTB.0 ' One-wire data pin
Mode_B Var PORTB.3 'Mode
UP_B Var PORTA.0 'Napred
DOWN_B Var PORTA.3 'Nazad
'*****************************************************************************
'Configs EasyPic5
'*****************************************************************************
TRISA=%00001001 ' 1-input
TRISB=%00001001 ' 0-input
'*****************************************************************************
'*****************************************************************************
' Variables
'*****************************************************************************
Temperature Var Word ' Temperature storage
TempC Var Word
Float Var Word
TargetTemp Var Word ' Desired Temperature
TargetTemp1 Var Word ' Desired Temperature
Hyst Var Word ' Hystereris
Hyst1 Var Word ' Hystereris
V Var Word ' Var. for display
B1 Var Byte ' Byte for TargetTemp calculation
B2 Var Byte ' Byte for TargetTemp calculation
B3 Var Byte ' Byte for TargetTemp calculation
B4 Var Byte ' Byte for TargetTemp calculation
B5 Var Byte ' Byte for TargetTemp calculation
B6 Var Byte ' Byte for TargetTemp calculation
Sign Var Byte ' +/- sign
Mode Var Byte ' 0=Temp. display, 1=Set Temp1, 2=Set Hysteresis1, 3=Set Temp2, 4=Set Hysteresis2
Twist Var Bit
'*****************************************************************************
' Resolution
'*****************************************************************************
DS18B20_9bit CON %00011111 ' 93.75ms, 0.5°C
DS18B20_10bit CON %00111111 ' 187.5ms, 0.25°C <-- My favorite
DS18B20_11bit CON %01011111 ' 375ms, 0.125°C
DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C (default)
DATA 46, 224, 20 ' Temp MSB, TEMP LSB, Hysteresis DIV 10
Re1=0 ' Warm Output Low
Re2=0 ' Cold Output Low
Mode=0 ' Temperature display mode
Twist = 0
PAUSE 500
LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
PAUSE 250
'*****************************************************************************
' DS 18B20 Config
'*****************************************************************************
OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit] 'Skip ROM search and write N_bits
' resolution to scratch pad
Read 0, B1 ' Read TargetTemp MSB
Read 1, B2 ' Read TargetTemp LSB
Read 2, B3 ' Read Hysteresis
Read 3, B4 ' Read TargetTemp MSB
Read 4, B5 ' Read TargetTemp LSB
Read 5, B6 ' Read Hysteresis
TargetTemp=B1*256+B2 ' Calculate TargetTemp value (Default=20.0 C.)
Hyst=10*B3 ' Calculate Hysteresis value (Default= 2.0 C.)
TargetTemp1=B3*256+B4 ' Calculate TargetTemp value (Default=20.0 C.)
Hyst1=10*B6 ' Calculate Hysteresis value (Default= 2.0 C.)
'********************podesavanje temperature************************************
Podesavanje:
If Mode_B=0 then ' Mode switch pressed
Pause 50 ' Debounce
LcdOut $FE, $8F, "*" ' Show that command is accepted
If Mode_B=0 then Podesavanje ' Wait until button is released
Mode=Mode+1 ' Increment mode
'----------------------
If Mode =3 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)
Write 2, Hyst / 10 ' Divide Hyst value to fit in Byte
EndIf
'*********************
If Mode =1 then ' Save Target Temperature (Mode1 -> Mode2)
Write 3, TargetTemp1 / 256 ' TargetTemp MSB
Write 4, TargetTemp1 MOD 256 ' TargetTemp LSB
EndIf
'----------------------
If Mode > 3 Then ' Save Hysteresis (Mode 2 -> Mode 0)
Mode=0 ' Only 0, 1, 2 are valid
Write 5, Hyst1 / 10 ' Divide Hyst value to fit in Byte
EndIf
EndIf
'********************
If Mode =0 then ' Set Target Temperature
LcdOut $FE, $80, "Set Temp1 " ' Show function
V=TargetTemp ' TargetTemp in V
Gosub SelectSign ' Select +/blank/-
Gosub DisplayTemp ' Display Target Temperature
If (UP_B=0) Or (DOWN_B=0) then ' Up or Down button pushed
If DOWN_B=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 UP_B=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
'--------------------
If Mode =1 then ' Set Hysteresis
LcdOut $FE, $80, "Hysteresys1 " ' Show function
Sign= " " ' No sign
V= 10000+Hyst ' Set value for V
Gosub DisplayTemp ' Display Hysteresis
If (UP_B=0) Or (DOWN_B=0) then ' Up or down button pushed
Sign= " " ' No sign for Hysteresis
If DOWN_B=0 then ' Down button
If Hyst > 10 then Hyst=Hyst-10 ' Not less than 0.1 C.
EndIf
If UP_B=0 then ' Up button
If Hyst < 1000 then Hyst=Hyst+10 ' Not more than 10.0 C.
EndIf
V= 10000+Hyst ' Set value for V
Gosub DisplayTemp ' Display Hysteresis
Pause 250 ' Delay 0.25 Sec.
EndIf
EndIf
'********************podesavanje temp2******************************************
If Mode =2 then ' Set Target Temperature
LcdOut $FE, $80, "Set Temp2 " ' Show function
V=TargetTemp ' TargetTemp in V
Gosub SelectSign ' Select +/blank/-
Gosub DisplayTemp ' Display Target Temperature
If (UP_B=0) Or (DOWN_B=0) then ' Up or Down button pushed
If DOWN_B=0 then ' Down button
If TargetTemp1 > 7500 then ' Not lower than -25 C. (10000-MinTemp * 100)
TargetTemp1=TargetTemp1-25 ' Decrease temperuture with 0.25 C.
EndIf
EndIf
If UP_B=0 then ' Up button
If TargetTemp1 < 17500 then ' Not higher than 75 C. (10000+MaxTemp * 100)
TargetTemp1=TargetTemp1+25 ' Increase temperature with 0.25 C.
EndIf
EndIf
GoSub SetTargetTemp1 ' Display TargetTemp and delay 0.25 Sec.
EndIf
EndIf
'--------------------
If Mode=3 then ' Set Hysteresis
LcdOut $FE, $80, "Hysteresys2 " ' Show function
Sign= " " ' No sign
V= 10000+Hyst1 ' Set value for V
Gosub DisplayTemp ' Display Hysteresis
If (UP_B=0) Or (DOWN_B=0) then ' Up or down button pushed
Sign= " " ' No sign for Hysteresis
If DOWN_B=0 then ' Down button
If Hyst1 > 10 then Hyst1=Hyst1-10 ' Not less than 0.1 C.
EndIf
If UP_B=0 then ' Up button
If Hyst1 < 1000 then Hyst1=Hyst1+10 ' Not more than 10.0 C.
EndIf
V= 10000+Hyst1 ' Set value for V
Gosub DisplayTemp ' Display Hysteresis
Pause 250 ' Delay 0.25 Sec.
EndIf
EndIf
If Mode > 0 then Podesavanje ' Setting TargetTemperature or Hysteresis
goto Podesavanje
' 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.
Temperature=V-10000
Else
Temperature=10000-V ' Below 0 C.
EndIf
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",178,"C "
Return
'-----------------------------------------
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DisplayTemp
Pause 250
Return
'-----------------------------------------
SetTargetTemp1:
V=TargetTemp1
Gosub SelectSign
Gosub DisplayTemp
Pause 250
Return