Ovaj kod za podesavanje vrednosti temperatura ne radi dobro.
-Kad ukljucim prikaze mi prazan lcd tek kad stisnem mode_B pojavi se set temp
-prelaz izmedju set temp i hysteresys je OK
-a da vratim izmedju hyteresis i set temp opet moram dva puta da stisnem
Sta ne valja?
Code: Select all
clear
DEFINE OSC 8 '8MHz << NOTICE UPPERCASE ON DEFINE
'END of timer/oscillator defines
OSCCON = %01110001 'Int CLK 8MHz
ANSEL = %00000000 'All digital
ANSELH = %00000000
OPTION_REG.7 = 1 'Weak pull-ups enabled
DEFINE LCD_DREG PORTD 'I/O port na kome se nalazi LCD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 1 'Register select pin
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 0 'Enable pin
DEFINE LCD_BITS 4 '4-bitni data bus
DEFINE LCD_LINES 2 'LCD ima dva reda karaktera
DEFINE BUTTON_PAUSE 100
'*****************************************************************************
'Pinout for EasyPic5
Mode_B Var PORTB.0 'podesi
UP_B Var PORTB.2 'podesi
DOWN_B Var PORTB.1 'podesi
symbol MO=PORTB.0 'Taster automatski SET/ENTER/MODE
symbol DN=PORTB.1 ' UP
symbol UP=PORTB.2 ' DOWN
symbol ST=PORTB.3 'Taster start/stop
'*****************************************************************************
TRISB= %00001111 ' RB0..RB2=Inputs, RB3..RB7=Outputs
' Variables
'*****************************************************************************
I var word
J var word
tmp1 var byte
tmp2 var byte
Temperature Var Word ' Temperature storage
TempC Var Word
Float Var Word
TargetTemp Var Word ' Desired Temperature
Hyst Var Word ' Hystereris
V Var Word ' Var. for display
B1 Var Byte ' Byte for TargetTemp calculation
B2 Var Byte ' Byte for TargetTemp calculation
Count_Remain Var Byte ' Count remaining
Count_Per_C Var Byte ' Count per degree C
Sign Var Byte ' +/- sign
Mode Var Byte ' 0=Temp. display, 1=Set Temp, 2=Set Hysteresis
Twist Var Bit
'-------------------------------------------------------------------------------
DATA 46, 224, 20 ' Temp MSB, TEMP LSB, Hysteresis DIV 10
Mode=0 ' Temperature display mode
Twist = 0
PAUSE 500
LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
PAUSE 250
Read 0, B1 ' Read TargetTemp MSB
Read 1, B2 ' Read TargetTemp LSB
TargetTemp=B1*256+B2 ' Calculate TargetTemp value (Default=20.0 C.)
Read 2, B1 ' Read Hysteresis
Hyst=10*B1 ' Calculate Hysteresis value (Default= 2.0 C.)
MainLoop:
If Mode_B=0 then ' Mode switch pressed
Pause 50 ' Debounce
LcdOut $FE, $8F, "*" ' Show that command is accepted
If Mode_B=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 ' Set Target Temperature
LcdOut $FE, $80, "Set Temp. " ' 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=2 then ' Set Hysteresis
LcdOut $FE, $80, "Hysteresys. " ' 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
if Mode > 0 then Mainloop ' Setting TargetTemperature or Hysteresis
goto mainloop ' Check again
' 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, $C6,$06
lcdout $fe, $70, $C,$12,$12,$C,$0,$0,$0,$0
lcdout $fe, $C7,"C"
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature
Return
'-----------------------------------------
SetTargetTemp:
V=TargetTemp
Gosub SelectSign
Gosub DisplayTemp
Pause 250
Return
'-----------------------------------------
END