Shop OBEX P1 Docs P2 Docs Learn Events
DS 1302: Set Date and Time using Push Buttons — Parallax Forums

DS 1302: Set Date and Time using Push Buttons

SELSEL Posts: 80
edited 2010-07-12 16:03 in Propeller 1
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

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-07-11 02:35
    SEL,

    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
  • SELSEL Posts: 80
    edited 2010-07-11 05:43
    Beau,

    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.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-07-11 07:05
    SEL,

    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.
  • localrogerlocalroger Posts: 3,452
    edited 2010-07-11 14:46
    You will end up using SetDateTime to change the RTC settings each time a change is commanded via the buttons. There are many ways of doing it, but in the end you will end up deciding to add 1 to one of the fields and to do that you'll read the current value, increment the field your user is setting, and writing the change to the RTC.
  • BRBR Posts: 92
    edited 2010-07-11 15:24
    SEL:

    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
  • SELSEL Posts: 80
    edited 2010-07-11 16:19
    My many thanks to all!

    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
  • BRBR Posts: 92
    edited 2010-07-11 16:45
    Updated my attachment above...see edit note.
  • SELSEL Posts: 80
    edited 2010-07-11 19:35
    BR,

    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
  • SELSEL Posts: 80
    edited 2010-07-11 20:10
    BR,

    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
  • SELSEL Posts: 80
    edited 2010-07-11 20:48
    I wish to thank everyone who was kind enough to give their ideas and time.

    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 SchwabeBeau Schwabe Posts: 6,568
    edited 2010-07-11 23:25
    It's nice to see things come together. Awesome job guys ... I suppose I'd better get that TIX clock working now hmmm? smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • SELSEL Posts: 80
    edited 2010-07-12 16:03
    Beau you and Chris have set the bar so high. You have helped so many. You are leaders of the highest caliber!

    Thanks for your help now and, no doubt, in the future!!

    SEL
Sign In or Register to comment.