Shop OBEX P1 Docs P2 Docs Learn Events
How to get DS1302 time & date in ASCII to scratch pad on BS... — Parallax Forums

How to get DS1302 time & date in ASCII to scratch pad on BS...

ArchiverArchiver Posts: 46,084
edited 2002-02-12 22:41 in General Discussion
In a message dated 2/11/02 9:19:08 PM Central Standard Time, clctable@a...
writes:


> How can I get DS1302 time & date in ASCII to scratch pad on BS2E ?
>
> If the Basic Stamp had string functions this would not be a problem.
>
> I have the DS1302 & program running, with the time and date being
> displayed with DEBUG.
>
> I need to have the date and time written in ASCII characters,
> either to the BS2E Scratch Pad, or to the RAM on the DS1302.
>
> ASCII characters are a must for my application.
>

Unlike PCs, most embedded controllers aren't connected to string oriented
devices ... so string functions are not particularly high on the list of
important things to do. That said, what you want to do is pretty simple with
a bit of code.

I won't post the whole program here (I did test this -- it works), just the
subroutine that will take your DS1302 data, convert it to string data and
store it in the SPRAM. You can use GET in a simple loop to send the ASCII
data to the DEBUG screen or to an LCD.

-- Jon Williams
-- Parallax

Clock_To_SPRAM:

' 012345678901234567890 ' SPRAM addresses
' ddd mm/dd/yy hh[noparse]:mm:[/noparse]ss ' string storage

FOR idx = 0 TO 2
READ (Day1 + ((day - 1) * 3) + idx), char
PUT idx, char
NEXT

PUT 3, " " ' change to 13 for CR

PUT 4, mo10 + "0" ' date
PUT 5, mo01 + "0"
PUT 6, "/"
PUT 7, dt10 + "0"
PUT 8, dt01 + "0"
PUT 9, "/"
PUT 10, yr10 + "0"
PUT 11, yr01 + "0"

PUT 12, " "

PUT 13, hr10 + "0" ' time
PUT 14, hr01 + "0"
PUT 15, ":"
PUT 16, mn10 + "0"
PUT 17, mn01 + "0"
PUT 18, ":"
PUT 19, sc10 + "0"
PUT 20, sc01 + "0"
RETURN



[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-02-12 06:14
    The subroutine works like a charm !
    Thank you,
    Michael

    --- In basicstamps@y..., jonwms@a... wrote:
    > In a message dated 2/11/02 9:19:08 PM Central Standard Time,
    clctable@a...
    > writes:
    >
    >
    > > How can I get DS1302 time & date in ASCII to scratch pad on BS2E ?
    > >
    > > If the Basic Stamp had string functions this would not be a
    problem.
    > >
    > > I have the DS1302 & program running, with the time and date being
    > > displayed with DEBUG.
    > >
    > > I need to have the date and time written in ASCII characters,
    > > either to the BS2E Scratch Pad, or to the RAM on the DS1302.
    > >
    > > ASCII characters are a must for my application.
    > >
    >
    > Unlike PCs, most embedded controllers aren't connected to string
    oriented
    > devices ... so string functions are not particularly high on the
    list of
    > important things to do. That said, what you want to do is pretty
    simple with
    > a bit of code.
    >
    > I won't post the whole program here (I did test this -- it works),
    just the
    > subroutine that will take your DS1302 data, convert it to string
    data and
    > store it in the SPRAM. You can use GET in a simple loop to send the
    ASCII
    > data to the DEBUG screen or to an LCD.
    >
    > -- Jon Williams
    > -- Parallax
    >
    > Clock_To_SPRAM:
    >
    > ' 012345678901234567890 ' SPRAM addresses
    > ' ddd mm/dd/yy hh[noparse]:mm:[/noparse]ss ' string storage
    >
    > FOR idx = 0 TO 2
    > READ (Day1 + ((day - 1) * 3) + idx), char
    > PUT idx, char
    > NEXT
    >
    > PUT 3, " " ' change to 13 for CR
    >
    > PUT 4, mo10 + "0" ' date
    > PUT 5, mo01 + "0"
    > PUT 6, "/"
    > PUT 7, dt10 + "0"
    > PUT 8, dt01 + "0"
    > PUT 9, "/"
    > PUT 10, yr10 + "0"
    > PUT 11, yr01 + "0"
    >
    > PUT 12, " "
    >
    > PUT 13, hr10 + "0" ' time
    > PUT 14, hr01 + "0"
    > PUT 15, ":"
    > PUT 16, mn10 + "0"
    > PUT 17, mn01 + "0"
    > PUT 18, ":"
    > PUT 19, sc10 + "0"
    > PUT 20, sc01 + "0"
    > RETURN
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-02-12 22:41
    At 06:14 AM 2/12/02 +0000, you wrote:
    >The subroutine works like a charm !
    >Thank you,
    >Michael


    Something to keep in mind and consider, it may not be your code at all.

    I found this in the Stamp archives of my own reply...


    At 08:35 AM 12/4/98 +0100, you wrote:
    >Hi,
    >
    > I have got a DS1302 , but could not find anywhere a 6pF crystal , and
    got a
    >12.5 pF one. Will this have any adverse effect on the DS1302 or is there
    any way
    >to get the capacitance from 12.5pF to 6pF ?
    >
    >Thanks,
    >Kevin
    >
    Panasonic carries the proper crystal. ...I have a DS1302 also, and they are
    VERY
    sensitive to the load capacitance. Using an 8pF I had about a 50% yield of
    whether
    or not the clock would oscillate. Of those that worked I could expect to
    loose 4
    minutes a day. (2 Hours a month!) Using 12.5pF, about the only thing I
    could do
    was set the trickle charge, the clock would not oscillate at all.



    Beau Schwabe Mask Designer IV - ATL
    National Semiconductor Wired Communications Division
    500 Pinnacle Court, Suite 525 Mail Stop GA1 Norcross, GA 30071
Sign In or Register to comment.