code question

can anyone tell me why this doesnt work
Code:
main:
readtemp C.2,b27 ; read value into b27
serout b.6,n2400,(254,128,#b27,"C") 
if b27<20 then  heat ; turn on heat source
if b27 >23 then heatoff 'turn off heat

heat:
 
high c.1 
high c.6
gosub main1

heatoff:

low c.1
low c.6
gosub main1
when this is run the temperature is read, and if less than 20 the heat is applied, temperature rises to 24 and heat is turned off. when the temp falls to 23 the heat comes back on again! so heat is switching on and off every few seconds. doesnt really matter but this means that its not doing what I tell it! cos I know better!!
The "main1" part of the program checks time and works fine.
D
 
OK heres the whole program
Code:
 ; b0 is switch 1
;b1 is i2c sda
;b2 is switch ;2
;b3 is switch 3
;b4 is i2c scl
;b5 is motor reverse relay
;b6 led display
;b7 infra red receiver

;c1 is 240 volt heat relay
;c0 is 12v volt power relay

;c7 infrared leds
;c6 circulation fan 

symbol seconds = b0
symbol mins =b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7 

                ;set ds1307 slave address
      
      i2cslave %11010000, i2cslow_8, i2cbyte
      
      ;initialise clock 
      
 let day =$01
 let year = $13
 let month = $02
 let date = $17
 let hour = $11
 let mins = $48
 let seconds = $00
 let control = %00010000
 
 writei2c 0, (seconds,mins,hour,day,date,month,year,control)
 
 
 ;read clock time
 readi2c 0, (seconds,mins,hour,day,date,month,year)
 ;report time

start: 
serout b.6,n2400, (254,1)
pause 30



main:
readtemp C.2,b27 ; read value into b27
serout b.6,n2400,(254,128,#b27,"C") 
if b27<20 then  heat ; turn on heat source
if b27 >23 then heatoff 'turn off heat

heat:
 
high c.1 
high c.6
gosub main1

heatoff:

low c.1
low c.6
gosub main1






main1:


	
	hi2cin 0, (b0,b1,b2,b3,b4,b5,b6)
	pause 100
	
	
	bcdtoascii b0,b19,b20		'Secs Convert to ASCII
	bcdtoascii b1,b8,b9		'Mins 
	bcdtoascii b2,b10,b11		'Hours
	bcdtoascii b3,b21,b22         'DayOfWeek;	
	bcdtoascii b4,b12,b13		'Date
	bcdtoascii b5,b14,b15		'Month
	bcdtoascii b6,b16,b17		'Year
	
	
      if b8 ="0" and b9 = "1" and b19="1" then gosub turneggs
	if b8 = "0" and b9 ="2" and b19="1"then gosub turneggsback
	if b8 = "0" and b9 = "3"and b19="1"then gosub turneggs
	if b8 ="0" and b9  ="4"and b19="1"  then gosub turneggsback
	
	
	
	
	serout b.6,n2400,(254,136)
	serout b.6,n2400,(b10,b11, ":",b8,b9,":",b19,b20)
	serout b.6,n2400,(254,200)
	serout b.6,n2400,(b12,b13,"/",b14,b15,"/",b16,b17,254,192)
	If b22="1" then serout b.6,n2400,(254,192,"Sun ")
	elseif b22="2" then serout b.6,n2400,("Mon ")
	elseif b22="3" then serout b.6,n2400,("Tue ")
	elseif b22="4" then serout b.6,n2400,("Wed ")
	elseif b22="5" then serout b.6,n2400,("Thur")
	elseif b22="6" then serout b.6,n2400,("Fri ")
	elseif b22="7" then serout b.6,n2400,("Sat ")
	endIf
      

goto	main





turneggs:
high c.0                          ;starts the turn motor
pause 500                        ; allows the Infrared sensor to get away from the IR led
high c.7  
                       ; turns on the IR leds
eggsturning:

if pinb.7 = 1 then turnoff        ;IR sensor  
if pinb.7 = 0 then eggsturning
turnoff:
low c.0
low c.7
   pause 8000                     
return



turneggsback:
high b.5
pause 30
high c.0
pause 500
high c.7
goto eggsturningback

eggsturningback:

if pinb.7 = 1 then turnoff1
if pinb.7 = 0 then eggsturningback

turnoff1:
low c.0
low b.5
pause 8000
return
 

nick12ab

Senior Member
can anyone tell me why this doesnt work
Code:
main:
readtemp C.2,b27 ; read value into b27
serout b.6,n2400,(254,128,#b27,"C") 
if b27<20 then  heat ; turn on heat source
if b27 >23 then heatoff 'turn off heat

heat:
 
high c.1 
high c.6
gosub main1

heatoff:

low c.1
low c.6
gosub main1
when this is run the temperature is read, and if less than 20 the heat is applied, temperature rises to 24 and heat is turned off. when the temp falls to 23 the heat comes back on again! so heat is switching on and off every few seconds. doesnt really matter but this means that its not doing what I tell it! cos I know better!!
The "main1" part of the program checks time and works fine.
D
There is nothing to prevent the code after the heat: label from being executed if b27 isn't > 27. You should use a goto main or goto main1 before the heat: label.

Also, you're using gosubs without any returns - use gotos instead.
 

srnet

Senior Member
Code:
doesnt really matter but this means that its not doing what I tell it!
Its doing exactly what you are telling it.

For temperatures of 21,22 and 23 both these tests fail, and the program carries onto the next line;

Code:
if b27<20 then  heat ; turn on heat source
if b27 >23 then heatoff 'turn off heat
So when the b27>23 test fails, because b27=23 the program continues from heat: onwards
 
Top