Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 clock integration problem — Parallax Forums

DS1302 clock integration problem

ArchiverArchiver Posts: 46,084
edited 2004-06-07 17:27 in General Discussion
hello all,
I have been working on a project that, amoung other things,
interfaces the DS1302 clock with a BS2p40. Once finished, the project will have an
initial setup routine that will ask the user to set the clock. I pretty much
just copied the code that parallax sends out with it...the problem is that I want
to set the time with a variable instead of setting "temp" directly equal to
some HEX value (see below).

.
.
.
Temp = $23 'set hours here
RTCCmd = HrsReg
GOSUB WriteRTC
.
.
.

how do i convert a decimal input from the user into something that will work
here??

thanks in advance!
Joe Casabona


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

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 11:33
    In a message dated 6/7/2004 10:28:57 AM Eastern Daylight Time,
    allan.lane@h... writes:


    > Note the 1302 uses "BCD" -- binary coded decimal.
    > This means its numbers go from
    > $00 to $09, then $10 to $19, then $20 to $29.
    > So, $10 means '10' in BCD, but in the BS2 this
    > value is really '16'.
    >

    Allan, the 1302 doesn't use BCD, but the DS1307 does.

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 12:45
    In a message dated 6/7/2004 11:43:36 AM Eastern Daylight Time,
    jwilliams@p... writes:


    > With respect, Sid, I believe the DS1302 DOES use BCD storage for values.
    > All of my programs for the DS1302 are written that way....
    >

    Jon, I am running 3 different DS1302 programs/applications, and none of them
    use BCD - just straight HEX.

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 13:40
    In a message dated 6/7/2004 12:30:50 PM Eastern Daylight Time,
    jwilliams@p... writes:


    > BCD is a method that stores a 0 to 9 value in each nibble of a byte --
    > using the HEX operators in PBASIC is a way to work with BCD registers
    > easily. If you wanted to preset the seconds register to 30, you would
    > put 3 in the upper nibble and zero in the lower nibble. The easiest way
    > to do this is
    >
    > secsReg = $30
    >
    > This handles things properly. The DS1302 does indeed use BCD storage,
    > the hex operators included in PBASIC just make it a bit easier.
    >

    Jon, as usual you are absolutely correct. What I was trying to say was that
    you do not need to convert from dec to BCD with the 1302 - just use the HEX
    operators and you have accomplished the same thing. And much easier. I suppose
    I could convert my 1307 program to HEX, but I will leave it in BCD so
    I will remember how to use BCD if I ever need it for something else.

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 14:23
    Note the 1302 uses "BCD" -- binary coded decimal.
    This means its numbers go from
    $00 to $09, then $10 to $19, then $20 to $29.
    So, $10 means '10' in BCD, but in the BS2 this
    value is really '16'.

    So, you'll need a decimal to BCD conversion.
    Which is:
    Number = 23 ' Number to be converted
    HighNib = Number / 10 ' Gives 2
    LowNib = Number // 10 ' Modulus operator -- gives 3

    MyBCD = HighNib * 16 + LowNib ' * 16 to put in top nibble.
    Temp = MyBCD

    --- In basicstamps@yahoogroups.com, joecasa@a... wrote:
    > hello all,
    > I have been working on a project that, amoung other things,
    > interfaces the DS1302 clock with a BS2p40. Once finished, the
    project will have an
    > initial setup routine that will ask the user to set the clock. I
    pretty much
    > just copied the code that parallax sends out with it...the problem
    is that I want
    > to set the time with a variable instead of setting "temp" directly
    equal to
    > some HEX value (see below).
    >
    > .
    > .
    > .
    > Temp = $23 'set hours here
    > RTCCmd = HrsReg
    > GOSUB WriteRTC
    > .
    > .
    > .
    >
    > how do i convert a decimal input from the user into something that
    will work
    > here??
    >
    > thanks in advance!
    > Joe Casabona
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 16:39
    With respect, Sid, I believe the DS1302 DOES use BCD storage for values.
    All of my programs for the DS1302 are written that way....

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=X0Ynr1ZNzgO28oWnhqYvJHXq07tu55emUPpGk-NQPUiyjUPhPegGSMounb2BIMR2nSv4gw]Newzed@a...[/url
    Sent: Monday, June 07, 2004 9:34 AM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Re: DS1302 clock integration problem


    In a message dated 6/7/2004 10:28:57 AM Eastern Daylight Time,
    allan.lane@h... writes:


    > Note the 1302 uses "BCD" -- binary coded decimal.
    > This means its numbers go from
    > $00 to $09, then $10 to $19, then $20 to $29.
    > So, $10 means '10' in BCD, but in the BS2 this
    > value is really '16'.
    >

    Allan, the 1302 doesn't use BCD, but the DS1307 does.

    Sid
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 17:27
    BCD is a method that stores a 0 to 9 value in each nibble of a byte --
    using the HEX operators in PBASIC is a way to work with BCD registers
    easily. If you wanted to preset the seconds register to 30, you would
    put 3 in the upper nibble and zero in the lower nibble. The easiest way
    to do this is

    secsReg = $30

    This handles things properly. The DS1302 does indeed use BCD storage,
    the hex operators included in PBASIC just make it a bit easier.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=uZy2mo4HnEmvKMMNaUbagCZbbAAK_STPRI7aYOmSMOOvWuB6w3a2Q5831SL__V4GI42SHZSuJvbR]Newzed@a...[/url
    Sent: Monday, June 07, 2004 10:46 AM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Re: DS1302 clock integration problem


    In a message dated 6/7/2004 11:43:36 AM Eastern Daylight Time,
    jwilliams@p... writes:


    > With respect, Sid, I believe the DS1302 DOES use BCD storage for
    > values. All of my programs for the DS1302 are written that way....
    >

    Jon, I am running 3 different DS1302 programs/applications, and none of
    them
    use BCD - just straight HEX.

    Sid
Sign In or Register to comment.