DS 1302: Set Date and Time using Push Buttons
SEL
Posts: 80
Does anyone have a schematic and code that would allow the layout and programing of the DS 1302 using hardware to set data and time?
Comments
There are several ways to do this, but you must decide which option will work best for you. Lets start off by asking how many buttons do you want to use?
Here is an example just using one button ... unfortunately the software for the TIX clock I wrote was on a computer that crashed. And I haven't had time to re-create the code, but from the video it should be fairly straight forward as far as the operation.
You-Tube TIX style clock video example
...basically you set two different thresholds for the button being pressed. When the button is pressed you increment a counter. Upon the release of the button, If the counter exceeds a pre-set 'first' threshold then increment the value for that particular digit, however if the counter exceeds a pre-set 'second' threshold then advance to the next digit. Reset the counter value and wait for the next button press.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/11/2010 2:58:51 AM GMT
I want to set:
Month, Day, Year, Dow and Hour, Minute, second.
I am not, at this point, cleaver enough with the hardware/software end.
Have you tried to use a hardware approach to the DS1302. Every body uses a serial terminal or software: SetDateTime(MM,DD,YY,DOW,Hour,Min,Second).
I need to create a stand along clock. The ideas running around in my head are rather ugly and not very practical.
I hope you can help.
Thank you for your response.
You could still do all of that from 1 button or several buttons. This depends on your personal preference.
Can you post code that you are currently looking at so that we can see what you are faced with? When you say that "Every body uses a serial terminal or software: SetDateTime(MM,DD,YY,DOW,Hour,Min,Second)", can you be more specific to your reference? In most cases it will require an additional PUB routine to monitor the buttons, and then perhaps another PUB routine to 'hook' into the existing code that accepts serial commands etc. but without looking at any code, that assumption may be incorrect.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I have been contemplating an LCD-based UI to set day/time for a project I'm working on. Wasn't planning on a 1-button type scheme, but Beau inspired me to give it a shot. It actually works surprisingly well and is simpler than the approach I was thinking of.
See attached, it may help.
EDIT: woopsy! Had the 10K resistor on the wrong side of my gnd connection in the schematic on lines 194-197 of attached. If you downloaded the original, don't use that schematic, as badness will ensue. Fixed now.
Post Edited (BR) : 7/11/2010 4:45:07 PM GMT
as for the push buttons: I have not tried to code that aspect of it yet. That was the reference to a lot of ugly thoughts roaming around in my head.
BR: Thank you for the example code. I will give that a look.
Beau S. and Chris S. are much appreciated, as are all who have taken the time to give good advice.
I do not mean to get messy, but this forum reminds me of the mid-seventies when I was first leaning to program Personal Computers.
It's a great fraternity!
SEL
Your 1 button solution works for cycling through the digits, but I can not get the setDateTime method to work.
Here is the Code:
pub setTime1Button
''routine to set ds1302 day time using a single button
''as suggested by Beau: http://forums.parallax.com/forums/default.aspx?f=25&m=468251
beau1button(button,@monthStr,month,1,12)
beau1button(button,@dayStr,day,1,31)
beau1button(button,@yearStr,year,10,30)
beau1button(button,@dowStr,dow,1,7)
beau1button(button,@hourStr,hour,0,23)
beau1button(button,@minuteStr,minute,0,59)
beau1button(button,@secondStr,second,0,59)
rtc.setDatetime(month, day, year, dow, hour, minute, second)
pub beau1button(buttonPin,strPtr,varSet,loLim,hiLim)|tmp
''1-button routine to set date and time
''press and release to increment digit
''press and hold to increment field
'set up to work with a single debounced button connected to the botton pin with a pullup
'output via 8X2 lcd driven using jm_lcd_ez object
'
' +3.3v ─[noparse][[/noparse]button]┳── button pin
'
' gnd
'
waitpeq(0,|<buttonPin,0) 'wait for button release
repeat
lcd.cls 'set day
lcd.str(strPtr)
lcd.gotoxy(1,2)
lcd.decx(varSet,2)
waitpeq(1,|<button,0) 'wait for button press
tmp := cnt
waitpeq(0,|<button,0) 'wait for button release
if cnt - tmp > increment_menu 'button held down > 2 sec?
return varSet 'yes, return value
else
varSet++ 'no, increment value
if varSet > hiLim
varSet := loLim
waitcnt(clkfreq/5 + cnt) 'check button state 5 times/sec
Here is the code I use to display date and time
repeat
Lcd.cls
rtc.readTime( @hour, @minute, @second ) ' read time from DS1302
rtc.readDate( @day, @month, @year, @dow ) 'read date from DS1302
Lcd.gotoxy(1,0)
lcd.str(lookup(dow:string("Sun"),string("Mon"),string("Tue"),string("Wed"){
},string("Thu"),string("Fri"),string("Sat")))
Lcd.str(string(": "))
Lcd.decx(month,2)
Lcd.str(string("-"))
Lcd.decx(day,2)
Lcd.str(string("-"))
Lcd.decx(year,2)
Lcd.gotoxy(0,1)
Lcd.str(string("Time: "))
Lcd.decx(hour,2)
Lcd.str(string(":"))
Lcd.decx(minute,2)
Lcd.str(string(":"))
Lcd.decx(second,2)
if not ina[noparse][[/noparse]button]
setTime1Button
You will note I use not ina[noparse][[/noparse]button]
I am using the PP Board for my development. When button is pressed the pin is pulled low to vss.
Any idea as to why I can't update date time?
Oh, I dowloaded your latest zip file and can not see changes?
I really like the one button concept!!
Please, advise.
SEL
I was able to get the clock up dated with the following code change:
pub setTime1Button
''routine to set ds1302 day time using a single button
''as suggested by Beau: http://forums.parallax.com/forums/default.aspx?f=25&m=468251
month := beau1button(button,@monthStr,month,1,12)
day := beau1button(button,@dayStr,day,1,31)
year := beau1button(button,@yearStr,year,10,30)
dow := beau1button(button,@dowStr,dow,1,7)
hour := beau1button(button,@hourStr,hour,0,23)
minute := beau1button(button,@minuteStr,minute,0,59)
second := beau1button(button,@secondStr,second,0,59)
rtc.setDatetime(month, day, year, dow, hour, minute, second)
Thank you so very much for putting me on the right track!!!!
SEL
Special thanks to BR for the button method!!
Attached is my final version, for the moment, for those who may find it of interest.
SEL
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for your help now and, no doubt, in the future!!
SEL