Back after a spell - it ain't easy !

manie

Senior Member
I have been "out" of Picaxe for a while but now I am back (not with a vengeance...). This is still for the "CHOOK-HOUSE" project.
I am having difficulties coding the DS1307 chip. This is what I get from Sertxd......

b2=20t=49u=52t2=1U2=434=14w9=1400
Time=135
Chg In Scan..
b2=20t=49u=52t2=1U2=434=14w9=1400
Time=136
Chg b2=20t=49u=52t2=1U2=434=14w9=1400
Time=136
Chgb2=20t=49u=52t2=1U2=434=14w9=1400
Time=137
The actual time is 14H00 + some minutes as w9 is showing.......
I have not added the minutes yet. If I do, something goes awry...........

Here is my code:

Code:
	readi2c 0,(b0,b1,b2)	'READ TIME : b0=$00,b1=$15,b2=$18 = example
	sertxd("b2=",#b2)
	bcdtoascii b2,tens,unit
	sertxd("t=",#tens,"u=",#unit)
	tens=tens-48:unit=unit-48
	sertxd("t2=",#tens,"U2=",#unit)
	tens=tens*10+unit
	sertxd("34=",#tens)
	put 34,tens				'hours-not ASCII but number
	w9=tens*100
	sertxd("w9=",#w9,cr,lf)				'convert from eg 18 to eg 1800
	put 512,w9
	bcdtoascii b1,tens,unit
	tens=tens-48:unit=unit-48
	tens=tens*10+unit
'	b1=tens*10+unit
	put 35,tens				'minutes
	get 512,w9				;get Hrs * 100 eg 1800
	w9=w9+tens
	sertxd("Time=",#w9,cr,lf)
	
	return
I read the RTC chip: I want the time to compare it to a stored ON time and a stored OFF time.
I have done this code to see what happens:
I want to use a time like 1830 or 2300 or 100 for 18h30/23h00/01h00 etc. 24 hr format.
What am I doing wrong ? It sure ain't easy..............
 

hippy

Ex-Staff (retired)
This is what I get from Sertxd......

b2=20t=49u=52t2=1U2=434=14w9=1400
It's quite hard to tell what's what because of the formatting, but it would seem you are displaying ASCII characters using # so seeing the ASCII values, not numeric values of the data.
 

SAborn

Senior Member
Manie: are those chook still alive after so long? Like have you checked if you still have any chooks left? ;)
 

Paix

Senior Member
I reckon that they will probably be third generation prospective dinners by now :)

I guess that you will be using the clock and daylight detection so that the chooks aren't let out too early in the summer as food for Reynard (clock limiting) and in the winter daylight limiting? Sort of agricultural office hours . . .
 

inglewoodpete

Senior Member
Wow you must have clever chooks if they are to work out the time to open and close their door!

It was too much for me, although its nearly midnight here. I suggest you encode the opening and closing times as BCD and compare the BCD from the RTC. Eg if the door is to open at 7:15am where hours = $07 and minutes = $15 or $0715. Using i2c, get hours into (say) b4 and minutes into b5 from the RTC. Then compare w2 with $0715. A match means open the door.

I'm sure there are simpler ways to encode and decode BCD than you have, (if you need to display the time for the chooks:rolleyes:). Do you need to make a big integer out of the time just to display it? Why not send each digit as an ASCII character after the BCDToASCII command?
 
Last edited:

hippy

Ex-Staff (retired)
Found the problem !!! Can you see it ?
Was it that the code is just far too complicated ? ;-)

My version for what you seemingly want to do is ...

HI2cIn 1, ( b0, b1 )
b0 = b0 / 16 * $FFFA + b0
b1 = b1 / 16 * $FFFA + b1
w9 = b1 * 100 + b0
SerTxd( "Time=", #w9, CR, LF )
 

manie

Senior Member
@Hippy

HI2cIn 1, ( b0, b1 )
b0 = b0 / 16 * $FFFA + b0
b1 = b1 / 16 * $FFFA + b1
w9 = b1 * 100 + b0
SerTxd( "Time=", #w9, CR, LF )
A bit advanced for an old timer like me, what does the " * $FFFA" do ?

Problem was I saved W9 in 512 without the the keyword " WORD "...........
Sorted now, will let you know how it goes.
 

manie

Senior Member
Thanks hippy ! Now that is what I call USEFULL CODE with USEFUL explanation !!! Thanks again..............
 
Top