Shop OBEX P1 Docs P2 Docs Learn Events
hex to dec conversion — Parallax Forums

hex to dec conversion

ArchiverArchiver Posts: 46,084
edited 2003-11-08 20:14 in General Discussion
Hi all,

Once again, not paying attention in math class bites me...

I am reciving the Julian date in BCD format from an Ultralink clock. I am
having problems converting it to dec format. I looked at Tracy's site, and
still couldn't get it to work. My code is like this:


rawYear var word


main:

serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays

goto main

Now, if I add a debug which says:

debug hex3 rawDays, cr

Of course I get the right number. I just can't seem to switch it to DEC
format.

Thanks!

Jonathan

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 18:58
    There are a few ways to do this. The most blatant one is:

    Euyear=(rawyear>>8)*100+((rawyear&$F0)>>4)*10 + (rawyear&$F)

    I think that will work. You could make it easier by reading the bytes
    separate:
    serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), a,b,c
    year=(a-"0")*100+(b-"0")*10+(c-"0")

    or maybe:

    serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), dec1 a, dec1 b, dec1 c
    year=a*100+(b*10)+c

    Something like that?

    Regards,

    Al Williams
    AWC
    *8 channels of PWM:
    http://www.al-williams.com/pak5.htm



    >
    Original Message
    > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=MgjnFERI5zVlxcBsrv1-XgLGuU1m4QlNFqp6IVxt1nku8LS9Or9qtRx4Ao7DZ9bp2zFSSfysDn36_Ndy]jpeakall@p...[/url
    > Sent: Friday, November 07, 2003 12:16 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] hex to dec conversion
    >
    >
    > Hi all,
    >
    > Once again, not paying attention in math class bites me...
    >
    > I am reciving the Julian date in BCD format from an Ultralink
    > clock. I am having problems converting it to dec format. I
    > looked at Tracy's site, and still couldn't get it to work. My
    > code is like this:
    >
    >
    > rawYear var word
    >
    >
    > main:
    >
    > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    >
    > goto main
    >
    > Now, if I add a debug which says:
    >
    > debug hex3 rawDays, cr
    >
    > Of course I get the right number. I just can't seem to switch
    > it to DEC format.
    >
    > Thanks!
    >
    > Jonathan
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 19:14
    Al,

    Substituting "days" for "years" in your code I get the same results I get
    from code I made using Tracy's site. The current day (Julian) is 310, but
    your code returns 011. I am doing days, not years, is that it?

    Thanks for the help,

    Jonathan

    Original Message
    From: "Al Williams" <alw@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, November 07, 2003 10:58 AM
    Subject: RE: [noparse][[/noparse]basicstamps] hex to dec conversion


    > There are a few ways to do this. The most blatant one is:
    >
    > Euyear=(rawyear>>8)*100+((rawyear&$F0)>>4)*10 + (rawyear&$F)
    >
    > I think that will work. You could make it easier by reading the bytes
    > separate:
    > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), a,b,c
    > year=(a-"0")*100+(b-"0")*10+(c-"0")
    >
    > or maybe:
    >
    > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), dec1 a, dec1 b, dec1 c
    > year=a*100+(b*10)+c
    >
    > Something like that?
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > *8 channels of PWM:
    > http://www.al-williams.com/pak5.htm
    >
    >
    >
    > >
    Original Message
    > > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=rCpFIz5gMk15Cx_8aTQW8h0bDtHziri59ZA1PODG7gi1EleRJPUobqH9DiKq90rWhpcJkU9H0VrwNL2tT64]jpeakall@p...[/url
    > > Sent: Friday, November 07, 2003 12:16 PM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] hex to dec conversion
    > >
    > >
    > > Hi all,
    > >
    > > Once again, not paying attention in math class bites me...
    > >
    > > I am reciving the Julian date in BCD format from an Ultralink
    > > clock. I am having problems converting it to dec format. I
    > > looked at Tracy's site, and still couldn't get it to work. My
    > > code is like this:
    > >
    > >
    > > rawYear var word
    > >
    > >
    > > main:
    > >
    > > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > >
    > > goto main
    > >
    > > Now, if I add a debug which says:
    > >
    > > debug hex3 rawDays, cr
    > >
    > > Of course I get the right number. I just can't seem to switch
    > > it to DEC format.
    > >
    > > Thanks!
    > >
    > > Jonathan
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 19:14
    >Hi all,
    >Once again, not paying attention in math class bites me...
    >I am reciving the Julian date in BCD format from an Ultralink clock. I am
    >having problems converting it to dec format. I looked at Tracy's site, and
    >still couldn't get it to work. My code is like this:
    >rawYear var word
    >
    >main:
    >serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    >goto main
    >Now, if I add a debug which says:
    >debug hex3 rawDays, cr
    >Of course I get the right number. I just can't seem to switch it to DEC
    >format.
    >Thanks!
    >Jonathan


    Hi Jonathan,

    The calculation goes as follows:

    decdays = rawdays.nib2 * 10 + rawdays.nib1 * 10 + rawdays.nib0
    DEBUG DEC decdays, CR
    That is the ordinal day of the year. The clock also gives a flag
    that tells if the current year is a leap year or not. The code here
    http://www.emesystems.com/BS2math4.htm#JulianDate
    describes how to change the ordinal date into YY:MM[noparse]:D[/noparse]D format.

    Which model clock are you using? <http://www.ulio.com> I have the
    older OEM model that Parallax used to sell, now seemingly
    discontinued. But the string you have, "wait("B"), hex3 rawDays"
    does not match what I was familiar with. The old OEM model had a
    choice of packed BCD or ascii BCD responses. I was quite hip to it
    at the time, because I was beta testing the interface.

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 19:23
    Doh. I always forget about the .nib stuff. I keep thinking in assembly and
    writing in Basic :-)

    Al Williams
    AWC
    * Easy RS232 prototyping:
    http://www.al-williams.com/rs1.htm


    >
    Original Message
    > From: Tracy Allen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Um5ldo24VLOKtUGvC__cmsCQm0_Ubg4j7LuD1g5Ch0UryQ8AWL-XzHzEiQaHf8gppaBunOKfyGAgzHIuLfU]tracy@e...[/url
    > Sent: Friday, November 07, 2003 1:15 PM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] hex to dec conversion
    >
    >
    > >Hi all,
    > >Once again, not paying attention in math class bites me...
    > >I am reciving the Julian date in BCD format from an
    > Ultralink clock. I
    > >am having problems converting it to dec format. I looked at Tracy's
    > >site, and still couldn't get it to work. My code is like
    > this: rawYear
    > >var word
    > >
    > >main:
    > >serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > >goto main
    > >Now, if I add a debug which says:
    > >debug hex3 rawDays, cr
    > >Of course I get the right number. I just can't seem to
    > switch it to DEC
    > >format. Thanks!
    > >Jonathan
    >
    >
    > Hi Jonathan,
    >
    > The calculation goes as follows:
    >
    > decdays = rawdays.nib2 * 10 + rawdays.nib1 * 10 + rawdays.nib0
    > DEBUG DEC decdays, CR
    > That is the ordinal day of the year. The clock also gives a flag
    > that tells if the current year is a leap year or not. The code here
    > http://www.emesystems.com/BS2math4.htm#JulianDate
    > describes how to change the ordinal date into YY:MM[noparse]:D[/noparse]D format.
    >
    > Which model clock are you using? <http://www.ulio.com> I have the
    > older OEM model that Parallax used to sell, now seemingly
    > discontinued. But the string you have, "wait("B"), hex3 rawDays"
    > does not match what I was familiar with. The old OEM model had a
    > choice of packed BCD or ascii BCD responses. I was quite hip to it
    > at the time, because I was beta testing the interface.
    >
    > -- Tracy
    >
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 19:52
    DecDays VAR WORD

    DecDays = (rawyear.Nib2 * 100) + (rawyear.Nib1 * 10) + rawyear.Nib0


    --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > There are a few ways to do this. The most blatant one is:
    >
    > Euyear=(rawyear>>8)*100+((rawyear&$F0)>>4)*10 + (rawyear&$F)
    >
    > I think that will work. You could make it easier by reading the
    bytes
    > separate:
    > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), a,b,c
    > year=(a-"0")*100+(b-"0")*10+(c-"0")
    >
    > or maybe:
    >
    > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), dec1 a, dec1 b, dec1 c
    > year=a*100+(b*10)+c
    >
    > Something like that?
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > *8 channels of PWM:
    > http://www.al-williams.com/pak5.htm
    >
    >
    >
    > >
    Original Message
    > > From: Jonathan Peakall [noparse][[/noparse]mailto:jpeakall@p...]
    > > Sent: Friday, November 07, 2003 12:16 PM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] hex to dec conversion
    > >
    > >
    > > Hi all,
    > >
    > > Once again, not paying attention in math class bites me...
    > >
    > > I am reciving the Julian date in BCD format from an Ultralink
    > > clock. I am having problems converting it to dec format. I
    > > looked at Tracy's site, and still couldn't get it to work. My
    > > code is like this:
    > >
    > >
    > > rawYear var word
    > >
    > >
    > > main:
    > >
    > > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > >
    > > goto main
    > >
    > > Now, if I add a debug which says:
    > >
    > > debug hex3 rawDays, cr
    > >
    > > Of course I get the right number. I just can't seem to switch
    > > it to DEC format.
    > >
    > > Thanks!
    > >
    > > Jonathan
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-07 20:06
    Hmm.. is it BCD or ASCII BCD. In other words, is 310 showing up as $310 or
    $33 $31 $30 (ASCII)?

    Your original code says:
    serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays

    The hex3 makes me think you are getting $33 $31 $30, right? Otherwise, that
    might be your problem right there.

    Al Williams
    AWC
    * Connect a PS/2 keyboard or mouse to any microcontroller:
    http://www.al-williams.com/pak6.htm


    >
    Original Message
    > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=XsedB05BzzBb9DLhjDzAWAFLCMqdAdsIQBR9Dkqj6hUELOgqVr36p5dhpx5goaRBVNlE7oQpx9DDzL0r2A]jpeakall@p...[/url
    > Sent: Friday, November 07, 2003 1:15 PM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] hex to dec conversion
    >
    >
    > Al,
    >
    > Substituting "days" for "years" in your code I get the same
    > results I get from code I made using Tracy's site. The
    > current day (Julian) is 310, but your code returns 011. I am
    > doing days, not years, is that it?
    >
    > Thanks for the help,
    >
    > Jonathan
    >
    >
    Original Message
    > From: "Al Williams" <alw@a...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Friday, November 07, 2003 10:58 AM
    > Subject: RE: [noparse][[/noparse]basicstamps] hex to dec conversion
    >
    >
    > > There are a few ways to do this. The most blatant one is:
    > >
    > > Euyear=(rawyear>>8)*100+((rawyear&$F0)>>4)*10 + (rawyear&$F)
    > >
    > > I think that will work. You could make it easier by reading
    > the bytes
    > > separate:
    > > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), a,b,c
    > > year=(a-"0")*100+(b-"0")*10+(c-"0")
    > >
    > > or maybe:
    > >
    > > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), dec1 a, dec1 b, dec1 c
    > > year=a*100+(b*10)+c
    > >
    > > Something like that?
    > >
    > > Regards,
    > >
    > > Al Williams
    > > AWC
    > > *8 channels of PWM:
    > > http://www.al-williams.com/pak5.htm
    > >
    > >
    > >
    > > >
    Original Message
    > > > From: Jonathan Peakall [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=XsedB05BzzBb9DLhjDzAWAFLCMqdAdsIQBR9Dkqj6hUELOgqVr36p5dhpx5goaRBVNlE7oQpx9DDzL0r2A]jpeakall@p...[/url
    > > > Sent: Friday, November 07, 2003 12:16 PM
    > > > To: basicstamps@yahoogroups.com
    > > > Subject: [noparse][[/noparse]basicstamps] hex to dec conversion
    > > >
    > > >
    > > > Hi all,
    > > >
    > > > Once again, not paying attention in math class bites me...
    > > >
    > > > I am reciving the Julian date in BCD format from an
    > Ultralink clock.
    > > > I am having problems converting it to dec format. I looked at
    > > > Tracy's site, and still couldn't get it to work. My code is like
    > > > this:
    > > >
    > > >
    > > > rawYear var word
    > > >
    > > >
    > > > main:
    > > >
    > > > serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > > >
    > > > goto main
    > > >
    > > > Now, if I add a debug which says:
    > > >
    > > > debug hex3 rawDays, cr
    > > >
    > > > Of course I get the right number. I just can't seem to
    > switch it to
    > > > DEC format.
    > > >
    > > > Thanks!
    > > >
    > > > Jonathan
    > > >
    > > >
    > > > To UNSUBSCRIBE, just send mail to:
    > > > basicstamps-unsubscribe@yahoogroups.com
    > > > from the same email address that you subscribed. Text in the
    > > > Subject and Body of the message will be ignored.
    > > >
    > > >
    > > > Your use of Yahoo! Groups is subject to
    > > > http://docs.yahoo.com/info/terms/
    > > >
    > > >
    > > >
    > > >
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in
    > the Subject
    > > and
    > Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-08 00:26
    Al, Tracy,

    The code you gave, of course, works. I just made a little program to watch
    all the math happen, and I think I get it. Maybe. Why wasn't I given the
    math gene?

    On your page it gives the formula:

    DD = DD.nib1 * 10 + DD.nib0 ' BCD to binary conversion of day

    Looking through the example code, I thought that would apply to me. Why
    doesn't it?

    I am using the old OEM module, the 325B, I think it is. The WAIT("B") is
    because the Stamp is actually receiving the data from a 433mHz receiver. I
    have the WWVB module hooked up to a 433mHz transmitter so that any of my
    projects that need the time can get it using a cheap receiver, with no need
    to include I/O or code for setting the time and date. It's a great system, I
    have three projects using it so far and more to come. All I need is to get
    the date going, (one of the projects finally needs more than the time) and
    with your and Al's help, I think I have it licked.

    Doh! I shouldn't have said that! Now I'll need to ask a question for sure!
    *knocks wood*


    Jonathan



    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, November 07, 2003 11:14 AM
    Subject: Re: [noparse][[/noparse]basicstamps] hex to dec conversion


    > >Hi all,
    > >Once again, not paying attention in math class bites me...
    > >I am reciving the Julian date in BCD format from an Ultralink clock. I am
    > >having problems converting it to dec format. I looked at Tracy's site,
    and
    > >still couldn't get it to work. My code is like this:
    > >rawYear var word
    > >
    > >main:
    > >serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > >goto main
    > >Now, if I add a debug which says:
    > >debug hex3 rawDays, cr
    > >Of course I get the right number. I just can't seem to switch it to DEC
    > >format.
    > >Thanks!
    > >Jonathan
    >
    >
    > Hi Jonathan,
    >
    > The calculation goes as follows:
    >
    > decdays = rawdays.nib2 * 10 + rawdays.nib1 * 10 + rawdays.nib0
    > DEBUG DEC decdays, CR
    > That is the ordinal day of the year. The clock also gives a flag
    > that tells if the current year is a leap year or not. The code here
    > http://www.emesystems.com/BS2math4.htm#JulianDate
    > describes how to change the ordinal date into YY:MM[noparse]:D[/noparse]D format.
    >
    > Which model clock are you using? <http://www.ulio.com> I have the
    > older OEM model that Parallax used to sell, now seemingly
    > discontinued. But the string you have, "wait("B"), hex3 rawDays"
    > does not match what I was familiar with. The old OEM model had a
    > choice of packed BCD or ascii BCD responses. I was quite hip to it
    > at the time, because I was beta testing the interface.
    >
    > -- Tracy
    >
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-08 04:47
    >On your page it gives the formula:
    >
    >DD = DD.nib1 * 10 + DD.nib0 ' BCD to binary conversion of day
    >
    >Looking through the example code, I thought that would apply to me. Why
    >doesn't it?

    It is BASICally the same. Except your example had three nibbles
    instead of two:
    serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays]
    That is because the day of the month only goes to a maximum of 31,
    while the number of days in a year can go up to 365.

    so you have to process three digits, the 100s, the 10s and the 1s.

    decdays = rawdays.nib2 * 10 + rawdays.nib1 * 10 + rawdays.nib0

    The formula assumes you are comfortable with the BASIC Stamp's left
    to right way of doing its math, which in most math books you would
    have to write with parens as follows:
    decdays = (rawdays.nib2 * 10 + rawdays.nib1) * 10 + rawdays.nib0
    so rawdays.nib2 ends up getting multiplied times 10*10. By the way,
    the Stamp produces the same code with and without the parentheses.

    Alan suggested a formula that sets it up a little differently, but
    gets exactly the same result:
    DecDays = (rawdays.Nib2 * 100) + (rawdays.Nib1 * 10) + rawdays.Nib0

    In this it is plain to see the place value of each nib as 100s, 10s and 1s.

    >I am using the old OEM module, the 325B, I think it is. The WAIT("B") is
    >because the Stamp is actually receiving the data from a 433mHz receiver. I
    >have the WWVB module hooked up to a 433mHz transmitter so that any of my
    >projects that need the time can get it using a cheap receiver, with no need
    >to include I/O or code for setting the time and date. It's a great system, I
    >have three projects using it so far and more to come. All I need is to get
    >the date going, (one of the projects finally needs more than the time) and
    >with your and Al's help, I think I have it licked.


    That's a neat idea. The original app we had for these was for a
    study out at Point Reyes Nat Park after the Mt. Vision fire, to time
    the incidence of runoff from the high slopes, to see how long it
    would take to build up a flash flood in the lower reaches near the
    bay. The data loggers at the high and low locations would have to
    have very accurately synchronized clocks. But the WWVB reception in
    the Canyons was impossible. Your idea of a "relay station" at the
    top might be workable for that kind of situation.

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-08 20:14
    BCD goes as:
    0x08, 0x09, then 0x10, 0x11
    Note this skips the values 0x0A..0x0F.

    Binary (and Hex) goes as:
    0x08, 0x09, 0x0A, 0x0B, ...

    So a BCD coded 'byte' can go from 0..99,
    while a 'true' binary number can go from
    00..FF, aka 0..256. Thus the conversion
    is needed. If you're talking about number
    of days per year, that's more than 256, so
    you need a third nibble for top 0,1, or 2.


    --- In basicstamps@yahoogroups.com, "Jonathan Peakall"
    <jpeakall@p...> wrote:
    > Al, Tracy,
    >
    > The code you gave, of course, works. I just made a little program
    to watch
    > all the math happen, and I think I get it. Maybe. Why wasn't I
    given the
    > math gene?
    >
    > On your page it gives the formula:
    >
    > DD = DD.nib1 * 10 + DD.nib0 ' BCD to binary conversion of day
    >
    > Looking through the example code, I thought that would apply to me.
    Why
    > doesn't it?
    >
    > I am using the old OEM module, the 325B, I think it is. The WAIT
    ("B") is
    > because the Stamp is actually receiving the data from a 433mHz
    receiver. I
    > have the WWVB module hooked up to a 433mHz transmitter so that any
    of my
    > projects that need the time can get it using a cheap receiver, with
    no need
    > to include I/O or code for setting the time and date. It's a great
    system, I
    > have three projects using it so far and more to come. All I need is
    to get
    > the date going, (one of the projects finally needs more than the
    time) and
    > with your and Al's help, I think I have it licked.
    >
    > Doh! I shouldn't have said that! Now I'll need to ask a question
    for sure!
    > *knocks wood*
    >
    >
    > Jonathan
    >
    >
    >
    >
    Original Message
    > From: "Tracy Allen" <tracy@e...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Friday, November 07, 2003 11:14 AM
    > Subject: Re: [noparse][[/noparse]basicstamps] hex to dec conversion
    >
    >
    > > >Hi all,
    > > >Once again, not paying attention in math class bites me...
    > > >I am reciving the Julian date in BCD format from an Ultralink
    clock. I am
    > > >having problems converting it to dec format. I looked at Tracy's
    site,
    > and
    > > >still couldn't get it to work. My code is like this:
    > > >rawYear var word
    > > >
    > > >main:
    > > >serin 7,17405,10,No_Data, [noparse][[/noparse]wait("B"), hex3 rawDays
    > > >goto main
    > > >Now, if I add a debug which says:
    > > >debug hex3 rawDays, cr
    > > >Of course I get the right number. I just can't seem to switch it
    to DEC
    > > >format.
    > > >Thanks!
    > > >Jonathan
    > >
    > >
    > > Hi Jonathan,
    > >
    > > The calculation goes as follows:
    > >
    > > decdays = rawdays.nib2 * 10 + rawdays.nib1 * 10 + rawdays.nib0
    > > DEBUG DEC decdays, CR
    > > That is the ordinal day of the year. The clock also gives a flag
    > > that tells if the current year is a leap year or not. The code
    here
    > > http://www.emesystems.com/BS2math4.htm#JulianDate
    > > describes how to change the ordinal date into YY:MM[noparse]:D[/noparse]D format.
    > >
    > > Which model clock are you using? <http://www.ulio.com> I have
    the
    > > older OEM model that Parallax used to sell, now seemingly
    > > discontinued. But the string you have, "wait("B"), hex3 rawDays"
    > > does not match what I was familiar with. The old OEM model had a
    > > choice of packed BCD or ascii BCD responses. I was quite hip to
    it
    > > at the time, because I was beta testing the interface.
    > >
    > > -- Tracy
    > >
    > >
    > >
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    Subject and
    > Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
Sign In or Register to comment.