Help with DS1307 and BS2p
fiveslo
Posts: 40
I've been successful in "hacking" various downloads from the internet to making my BS2p talk with the DS1307... However now that I'm in the final stages of designing my ON/OFF timer with the '1307, I've found that my "clock" is acting really weird.· By this I mean that for instance if I set a date of say 04/27/2005, the clock/program come up correctly.. however when the time reaches 23:59:59 and then cycles to the so called next day.... the clock continues normally... however the date now becomes 04/20/2005.... this weird circumstance occurs no matter what month I set!!!! This also happens on later days of the month... such as 25 becomes 32, 29 becomes 24, and other wild and crazy numbers!!!· Also when I put in 02/28/2005 and the clock cycles past midnight, guess what I get 02/29/2005... The data sheet for the DS1307 states that its leap year compliant... what gives???· I believe I'm not properly "clearing" the registers of the DS1307 when I write to them after I input my new clock settings ie: new time, new date, etc... Is there a simple way of clearing all the registers prior to writing to them??· My snippet for reading the DS1307 is below... Can anyone please help
Main:
··· GOSUB Get_Time····························· 'get current time
··· GOSUB Read_MemKey_Offtime_Presets·········· 'read MemKey Offtime Presets
··· IF secs=80 THEN Clock_Not_Set
··· SEROUT LCD, N9600, [noparse][[/noparse]PosCmd, 64, DEC2 month, "/", DEC2 day, "/20", DEC2 year]
··· SEROUT LCD, N9600, [noparse][[/noparse]PosCmd, 76,DEC2 hrs,":", DEC2 mins, ":", DEC2 secs]
the Get_Time subroutine is duplicated in multiple banks....
....... Another Bank to Set Date......
Get_Time:
· I2CIN SDA, Rd1307, 0, [noparse][[/noparse]secs, mins, hrs,date,day,month,year]····· ' read time registers
· secs = secs.NIB1 * 10 + secs.NIB0········································ ' BCD to decimal
· mins = mins.NIB1 * 10 + mins.NIB0
· hrs = hrs.NIB1 * 10 + hrs.NIB0
· RETURN
Set_DS1307:
· secs = (secs / 10 << 4) + (secs // 10)···································· 'decimal to BCD
· mins = (mins / 10 << 4) + (mins // 10)
· hrs· = (hrs / 10 << 4) + (hrs // 10)
··I2COUT SDA, Wr1307, 0, [noparse][[/noparse]secs,mins,hrs,date,day,month,year]····· 'update time registers
· RETURN
Please help anyone..... Rob
Main:
··· GOSUB Get_Time····························· 'get current time
··· GOSUB Read_MemKey_Offtime_Presets·········· 'read MemKey Offtime Presets
··· IF secs=80 THEN Clock_Not_Set
··· SEROUT LCD, N9600, [noparse][[/noparse]PosCmd, 64, DEC2 month, "/", DEC2 day, "/20", DEC2 year]
··· SEROUT LCD, N9600, [noparse][[/noparse]PosCmd, 76,DEC2 hrs,":", DEC2 mins, ":", DEC2 secs]
the Get_Time subroutine is duplicated in multiple banks....
....... Another Bank to Set Date......
Get_Time:
· I2CIN SDA, Rd1307, 0, [noparse][[/noparse]secs, mins, hrs,date,day,month,year]····· ' read time registers
· secs = secs.NIB1 * 10 + secs.NIB0········································ ' BCD to decimal
· mins = mins.NIB1 * 10 + mins.NIB0
· hrs = hrs.NIB1 * 10 + hrs.NIB0
· RETURN
Set_DS1307:
· secs = (secs / 10 << 4) + (secs // 10)···································· 'decimal to BCD
· mins = (mins / 10 << 4) + (mins // 10)
· hrs· = (hrs / 10 << 4) + (hrs // 10)
··I2COUT SDA, Wr1307, 0, [noparse][[/noparse]secs,mins,hrs,date,day,month,year]····· 'update time registers
· RETURN
Please help anyone..... Rob
Comments
It looks like the program also needs to convert the date from BCD to decimal, just like it does with the time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
NEW! 4 MB EEPROM
http://hometown.aol.com/newzed/page4.html
·
I've attached a simple DS1307 demo that shows the conversions to and from BCD.· See the Set_Time (decimal to BCD) and Get_Time (BCD to decimal) routines.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
NEW! 4 MB EEPROM
http://hometown.aol.com/newzed/page4.html
Decimal to BCD:
· bcdNum = (decNum / 10 << 4) + (decNum // 10)
BCD to Decimal:
· decNum = (bcdNum.NIB1 * 10) + bcdNum.NIB0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Post Edited (Jon Williams) : 4/29/2005 1:31:53 PM GMT
number to number".· My program works with the DS1307 and that was the object.· Am I missing something?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
NEW! 4 MB EEPROM
http://hometown.aol.com/newzed/page4.html
·
I also use the hex2 modifier in the input stage
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
· bcdNum = (decNum / 10 << 4) + (decNum // 10)
· decNum = (bcdNum.NIB1 * 10) + bcdNum.NIB0
In any case, I've added the conversions to the day, date, month and year registers for both the read and write subroutines for my BS2P program, later tonight or should I say earlier tomorrow morning I'll download and try the newly updated program... I'll try to post my results to this almost finished project.... Thanks again.. Rob
I express my gratitude to all who have replied to my posting·and giving the solution to my problem.·Especially·Tracy and Jon...··After adding the conversions (ie: bcdNum or decNum) to the date, day, month, year variables in all the areas that either read or write to the DS1307.· This project, in case anyone is interested, is a program that I have written which will look at the current day, and then lookup the current day in a table to find its local area sunset time, which will be the turn on time for timer one.· The program will then add ten minutes to the current days sunset time, this will be the turn on time for timer two.· All "data" will be input to the BS2p via a 3x4 keypad that is interfaced thru a MemKey module, that I've purchased so long ago, and completely lost track of why I originally purchased it, figured this would be the time to use it.·· All information so far is being viewd on a 4x20 backlighted serial LCD, which will most likely end up in the final project...· Also turn off times are fully programmable and I suppose if I wanted I could also add multiple turn on/off times.... The only reason the whole project came about was the·fact that I became very sick of constantly adjusting and readjusting the mechanical timers for outside lighting around my house, and figured this was the way to·go after "playing" with the BS2 for so many years...· Once again thank you for all your input and your answers to my problem... Rob
Some of my customers are studying bats, and the monitoring equipment has to run from a little before sunset to a little after sunrise. The Stamp controls the power, so it has to have those local times entered for each location. We got tired of coding in the data tables. I found a superb Excel spreadsheet online (users.vei.net/pelican/sunrise.html by Greg Pelletier) that has set of VB macros for all that, so I added a worksheet that allows us to enter a location and a base date, and the spreadsheet generates all the Stamp DATA statements, as well as a BS2pe slot program to return the sunrise and sunset time for any given date 9 years into the future for that location. Maybe I'll put that on my web site, if others could make use of it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Could you please post the worksheet that you've added to the Excel sheet you recommeded in your last email.· I'd very much be interested in this, since I was actually considering doing exactly as you described... rewriting all the sunset data for each year, that·is a "flaw" that I see in this whole project, that will consume alot of time to recreate each and every year, for each and every location.... If this is as you describe... it would be of great help ... Thank you... Rob
·