Rainwater tank controller

lewisg

Senior Member
...simply use two separate let and pulsout commands.
Why not allow let to go ahead and die?

Isn't x = 10 the same as let x = 10? I use several different dialects of BASIC and I'm fairly sure haven't used let since the late 70's.
 

premelec

Senior Member
Let's do it...

I agree though x = x + 2 is a bit dicey sounding and let lets you do any foolishness! [Let there be light!]
 

nick12ab

Senior Member
I looked up the LET command in the manual but I don`t understand how to use it in this instance. Can you give an example?
It's the command you're using when you write this: lcddata = b20

For this instance the code I mentioned can be replaced with:
Code:
low rs
	lcddata = %00000010 : pulsout ENT,2	:pause 10				'move cursor home
	lcddata = 144 : pulsout ENT,2							        '128 + cursor moves
        high RS
	lcddata = b19 : pulsout ENT,2
	lcddata = b20 : pulsout ENT,2
	end
 

marzan

Senior Member
Hi folks. Just going through and tidying up the code I have written so far. Am I correct in assuming that "lcddata = %00000010" is the same as "lcddata = 2" ? I have been using both, but maybe it would be more understandable if it was one or the other.

Thanks.
Marz.
 

premelec

Senior Member
Sure %10 = 2; different notations for the same number. And yes it often is more understandable in context to use one or the other as appropriate.
 

marzan

Senior Member
Ok. Here is the code to set the time, bypass time, daylight saving and display the results on an OLED:
It is running on a 28X2
pin C.0 is accept/menu
pin c.1 is down/lower number
pin c.2 is up/higher number

Code:
	SYMBOL   BL = c.5												;BACKLIGHT
	SYMBOL   RS = C.6				
	SYMBOL  ENT = c.7
	SYMBOL lcddata = pinsb
	SYMBOL seconds = b10											;RTC stored value
	SYMBOL mins = b11												;RTC stored value
	SYMBOL hour = b12												;RTC stored value
	SYMBOL BYPASSHR = b15										



setup:
	
	
	BYPASSHR = 8
	dirsb = 255 												;set pinsb to output
	dirsc = 7      												;set pinsc
	
	high BL                       									;turn on backlight
		
	low RS													;command register
	
	pause 100
	
	lcddata = 1 : pulsout ENT,2	:pause 10								'Clear display
	lcddata = 56 : pulsout ENT,2	:pause 10								'Function Set: 8-bit, 2 lines, font 8x5	
	lcddata = 12 : pulsout ENT,2	:pause 10								'Display on/off control: Display on, cursor off, blink off
	lcddata = 6 : pulsout ENT,2	:pause 10								'Entry mode set: Increment, cursor shift

WELCSCREEN:	
	PAUSE 200												;set PICAXE as master and DS1307 slave address

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte						'set up RTC on I2C										
	hi2cin 0,(b10,b11,b12)											'read RTC
	pause 50

	low rs													'command register
	lcddata = 2 : pulsout ENT,2										'return home
	pause 10							
	lcddata = 128 : pulsout ENT,2										'Line 1
	high rs													'Data register
		for b4 = 0 to 16
		lookup b4,("  TANK CONTROLLER"),lcddata
		pulsout ENT,2
		next
	low rs													'command register
	lcddata = 192 : pulsout ENT,2										'Line 2
															'data register
	BCDTOASCII b12,b19,b20											'Change BCD to ASCII for transmission to LCD
	BCDTOASCII b11,b21,b22
	BCDTOASCII b10,b23,b24
	
	high rs
		for b4 = 0 to 25
		lookup b4,("   TIME ",b19,b20,":",b21,b22,":",b23,b24,"    <-MENU"),lcddata
		pulsout ENT,2
		next
	if pinc.0 = 1 then goto SETMENU1				
	goto WELCSCREEN							
										
SETMENU1:
	Pause 400
	gosub SCREENCLR	
		for b4 = 0 to 38
		lookup b4,("* SET CLOCK           IRRIGATION BYPASS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 25
		lookup b4,("  DAYLIGHT SAVING     BACK"),lcddata
		pulsout ENT,2
		next
	wait 1
		do
		if pinc.0 = 1 then goto RTCSETSCRHR								'menu screen to set clock
		if pinc.1 = 1 then goto SETMENU2          				     	      'xxxx
		loop
	
SETMENU2:
	Pause 400
	gosub SCREENCLR
		for b4 = 0 to 38
		lookup b4,("  SET CLOCK           IRRIGATION BYPASS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 25
		lookup b4,("* DAYLIGHT SAVING     BACK"),lcddata
		pulsout ENT,2
		next
	wait 1
		do
		if pinc.0 = 1 then goto DAYSAVSET1
		if pinc.2 = 1 then goto SETMENU1
		if pinc.1 = 1 then goto SETMENU3
		loop
	
SETMENU3:
	Pause 400
	gosub SCREENCLR
		for b4 = 0 to 38
		lookup b4,("  SET CLOCK         * IRRIGATION BYPASS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 25
		lookup b4,("  DAYLIGHT SAVING     BACK"),lcddata
		pulsout ENT,2
		next
	wait 1
		do
		if pinc.0 = 1 then goto IRRIGOVERIDE
		if pinc.2 = 1 then goto SETMENU2
		if pinc.1 = 1 then goto SETMENU4
		loop
	
SETMENU4:
	Pause 400
	gosub SCREENCLR	
		for b4 = 0 to 38
		lookup b4,("  SET CLOCK           IRRIGATION BYPASS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 25
		lookup b4,("  DAYLIGHT SAVING   * BACK"),lcddata
		pulsout ENT,2
		next
	wait 1
		do
		if pinc.0 = 1 then LOW RS :lcddata = 1 : pulsout ENT,2 :goto WELCSCREEN
		if pinc.2 = 1 then goto SETMENU3
		ENDIF
		loop
	

RTCSETSCRHR:
	
	pause 400
	gosub SCREENCLR	
		for b4 = 0 to 10
		lookup b4,("* SET HOURS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("  SET MINUTES       <-ACCEPT"),lcddata
		pulsout ENT,2
		next
	low rs
	lcddata = 2 : pulsout ENT,2	:pause 10								'move cursor home
	lcddata = 13 : pulsout ENT,2	:pause 1								'blink cursor
	lcddata = 144 : pulsout ENT,2										'128 + cursor moves
	high RS
		for b4 = 0 to 1
		lookup b4,(b19,b20),lcddata : pulsout ENT,2
		next
			do
			if pinc.1 = 1 then dec b12 
			elseif pinc.2 = 1 then inc b12 
			elseif pinc.0 = 1 then goto RTCSETSCRMIN
			endif
			hi2cout 0,(b10,b11,b12)									'WRITE RTC
			BCDTOASCII b12,b19,b20
			low rs
			lcddata = 2 : pulsout ENT,2	:pause 10						'move cursor home
			lcddata = 13 : pulsout ENT,2	:pause 1						'blink cursor
			lcddata = 144 : pulsout ENT,2								'128 + cursor moves
			high RS
			lcddata = B19 : pulsout ENT,2	:pause 1
			lcddata = B20 : pulsout ENT,2	:pause 1
			pause 200
       		loop
       		
RTCSETSCRMIN:
	pause 400
	gosub SCREENCLR	
		for b4 = 0 to 10
		lookup b4,("  SET HOURS"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("* SET MINUTES       <-ACCEPT"),lcddata
		pulsout ENT,2
		next
	low rs
	lcddata = 2 : pulsout ENT,2	:pause 10							'move cursor home
	lcddata = 131 : pulsout ENT,2	:pause 1							'blink cursor
	lcddata = 208 : pulsout ENT,2										'128 + cursor moves
	high RS
		for b4 = 0 to 1
		lookup b4,(b21,b22),lcddata : pulsout ENT,2
		next
			do
			if pinc.1 = 1 then dec b11 
			elseif pinc.2 = 1 then inc b11 
			elseif pinc.0 = 1 then goto SETMENU1
			endif
			hi2cout 0,(b10,b11,b12)					'WRITE RTC
			BCDTOASCII b11,b21,b22
			low rs
			lcddata = 2 : pulsout ENT,2	:pause 10					'move cursor home
			lcddata = 13 : pulsout ENT,2	:pause 1					'blink cursor
			lcddata = 208 : pulsout ENT,2								'128 + cursor moves
			high RS
			lcddata = B21 : pulsout ENT,2	:pause 1
			lcddata = B22 : pulsout ENT,2	:pause 1
			pause 100
       		loop

DAYSAVSET1:
	pause 400
	gosub SCREENCLR	
		for b4 = 0 to 27
		lookup b4,("* FORWARD 1 HOUR      CANCEL"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("  BACK 1 HOUR       <-ACCEPT"),lcddata
		pulsout ENT,2
		next
			do
			if pinc.0 = 1 then inc b12  
			hi2cout 0,(b10,b11,b12)									'WRITE RTC
			goto SETMENU1
			elseif pinc.1 = 1 then goto DAYSAVSET2 
			endif					
			pause 100
       		loop

DAYSAVSET2:
	pause 400
	gosub SCREENCLR	
		for b4 = 0 to 27
		lookup b4,("  FORWARD 1 HOUR      CANCEL"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("* BACK 1 HOUR       <-ACCEPT"),lcddata
		pulsout ENT,2
		next
			do
			if pinc.0 = 1 then dec b12 
			hi2cout 0,(b10,b11,b12)									'WRITE RTC
			goto SETMENU1
			elseif pinc.2 = 1 then goto DAYSAVSET1 
			elseif pinc.1 = 1 then goto DAYSAVSET3
			endif
			pause 100
       		loop


DAYSAVSET3:
	pause 400
	gosub SCREENCLR	
		for b4 = 0 to 27
		lookup b4,("  FORWARD 1 HOUR    * CANCEL"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("  BACK 1 HOUR       <-ACCEPT"),lcddata
		pulsout ENT,2
		next
			do
			if pinc.0 = 1 then low RS :lcddata = 1 : pulsout ENT,2	:pause 10 :GOTO SETMENU1
			elseif pinc.2 = 1 then GOTO DAYSAVSET2
			endif
			pause 100
       		loop
	



SCREENCLR:		
	low rs
	lcddata = 1 : pulsout ENT,2									'Clear display
	pause 10
	lcddata = 2 : pulsout ENT,2									'reuturn home
	PAUSE 10
	lcddata = 128 : pulsout ENT,2											'line 1
	pause 10
	high rs
	RETURN
	

IRRIGOVERIDE:
pause 400
	gosub SCREENCLR	
		for b4 = 0 to 30
		lookup b4,("     SET TIME               :00"),lcddata
		pulsout ENT,2
		next
	LOW RS
	lcddata = 192 : pulsout ENT,2
	pause 10
	high rs
		for b4 = 0 to 27
		lookup b4,("    FOR BYPASS      <-ACCEPT"),lcddata
		pulsout ENT,2
		next
			do
			low RS
			lcddata = 2 : pulsout ENT,2							'reuturn home
			PAUSE 10
			lcddata = 154 : pulsout ENT,2							'128 + cursor moves
			PAUSE 10							
			BCDTOASCII b15,b19,b20
			high RS
			lcddata = B19 : pulsout ENT,2	:pause 1
			lcddata = B20 : pulsout ENT,2	:pause 1
			low RS
			pause 200
			if pinc.1 = 1 then dec b15 
			elseif pinc.2 = 1 then inc b15						
			elseif pinc.0 = 1 then lcddata = 1 : pulsout ENT,2 :pause 10 :goto SETMENU1								'Clear display:goto WELCSCREEN
			endif
       		loop
If there are any tips on simplifying it I would be grateful to know. The only issue I haven`t been able to figure out is when the time from the RTC is converted from BCD to ASCII, when adjusting the time it goes from 1 to 9 and then :, ;, <, =, >, and ? I figure it has converted to hex, but thats only a guess. Any tips to fix this?
Marz.
 
Top