PDA

View Full Version : need help with temperature and ventilation control



aladdin_2005
- 4th November 2007, 20:44
hi all
the code
############################################

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 5
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 250
;===============================================
Digit var Byte
mask var Byte
b0 var byte
wa var WORD
i var byte
tempr var word
; temp0 var tempr.byte1
adval var word ' Create adval to store result
fan11 var byte
fan22 var byte
fan33 var byte
Volts var word
Samples var word ' Samples
Sample var byte ' Sample
Vin var Word ' Vin is variable
;================================================
stor var portc.0
up var portc.1
down var portc.2
selct var portc.3
heater var portc.4
fana1 var portc.5
fana2 var portc.6
fana3 var portc.7
;================================================
TRISA = %00001011
TRISB = %00000000
TRISC = %00001111
;================================================
clear
Read 1,wa
Read 2,fan11
Read 3,fan22
Read 4,fan33
;================================================
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
;================================================
ADCON1 = %10000101 ' set port a analog and a3 vref
;================================================
main:
gosub getemp
gosub showtemp
GOSUB SCANSW
gosub chekrel
pause 100
goto main
;================================================
getemp:
Pause 1
if ADCON0.2 = 1 Then MAIN
ADCIN 0,Vin
Vin=(Vin* 24)
vin = vin / 100
tempr = vin
pause 300
return
;================================================
showtemp:
Lcdout $fe, 1
LCDOUT $FE,2
; Lcdout "Temp=",DEC (Vin DIG 3),DEC (Vin DIG 2),".",DEC (Vin dig 1),DEC (Vin dig 0),"C"
lcdout "temp = " , dec tempr , " C"
LCDOUT $FE,$C0 'LOCATE LINE 2
Lcdout "hi eng twakal"
pause 300
return
;================================================
SCANSW:
if selct = 0 then goto loop1
return
;================================================
temp:
lcdout $fe,1
lcdout " you set heater "
LCDOUT $FE,$C0
lcdout "new vol = " , dec wa," C"
if up = 0 then wa = wa+1
if down = 0 then wa = wa-1
if stor = 0 then write 1,wa
if selct =0 then loop2
pause 300
;return
goto temp
;================================================
fan1:
lcdout $fe,1
lcdout " you set fan1 "
LCDOUT $FE,$C0
lcdout "new vol = " , dec fan11," C"
if up = 0 then fan11 = fan11+1
if down = 0 then fan11 = fan11-1
if stor = 0 then write 2,fan11
if selct = 0 then goto loop3
pause 300
goto fan1
;================================================
fan2:
lcdout $fe,1
lcdout " you set fan2 "
LCDOUT $FE,$C0
lcdout "new vol = " , dec fan22," C"
if up = 0 then fan22 = fan22+1
if down = 0 then fan22 = fan22-1
if stor =0 then write 3,fan22
if selct =0 then goto loop4
pause 300
goto fan2
;================================================
fan3:
lcdout $fe,1
lcdout " you set fan3 "
LCDOUT $FE,$C0
lcdout "new vol = " , dec fan33," C"
if up = 0 then fan33 = fan33+1
if down = 0 then fan33 = fan33-1
if stor =0 then write 4,fan33
if selct =0 then goto loop5
pause 300
goto fan3
;================================================
loop1:
if selct = 1 then goto temp
goto loop1
;================================================
loop2:
if selct = 1 then goto fan1
goto loop2
;================================================
loop3:
if selct = 1 then goto fan2
goto loop3
;================================================
loop4:
if selct = 1 then goto fan3
goto loop4
;================================================
loop5:
if selct = 1 then goto main
goto loop5
;================================================
chekrel:
goto heat
goto fa1
goto fa2
goto fa3
;return
;================================================
heat:
if tempr <= wa then heater = 1
if tempr >= wa then heater = 0
pause 30
;return
;================================================
fa1:
if tempr <= fan11 then fana1 = 0
if tempr >= fan11 then fana1 = 1
pause 30
;return
;================================================
fa2:
if tempr <= fan22 then fana2 = 0
if tempr >= fan22 then fana2 = 1
pause 30
;return
;================================================
fa3:
if tempr <= fan33 then fana3 = 0
if tempr >= fan33 then fana3 = 1
pause 30
return
;================================================
end
##################################################
the problem
heater only (off - on)
I want work fan1 - fan2 - fan3

Regards
aladdin

mackrackit
- 5th November 2007, 16:13
;================================================
heat:
if tempr <= wa then heater = 1
if tempr >= wa then heater = 0
pause 30
;return
;================================================
fa1:
if tempr <= fan11 then fana1 = 0
if tempr >= fan11 then fana1 = 1
pause 30
;return
;================================================
fa2:
if tempr <= fan22 then fana2 = 0
if tempr >= fan22 then fana2 = 1
pause 30
;return
;================================================
fa3:
if tempr <= fan33 then fana3 = 0
if tempr >= fan33 then fana3 = 1
pause 30
return
;================================================
end

If all is working like you want with the exception of the fans and the heater is working...
wa is word size and fan11/22/33 are byte size.

Could be some thing else but off the top that is what jumps out.

aladdin_2005
- 5th November 2007, 19:36
hi mackrackit
thanks
the hard ware my project...

http://img249.imageshack.us/img249/5427/testthermostatlcdcopyps5.jpg