Shop OBEX P1 Docs P2 Docs Learn Events
BCD -> Dec — Parallax Forums

BCD -> Dec

ArchiverArchiver Posts: 46,084
edited 2003-04-11 19:18 in General Discussion
The register data (in BCD) from a Dallas 1302 RTC,
displays nicely on a BS2 Debug screen with the
following code:

'Display RTC Time and Date
Debug Home,Dec Hours.HighNib,Dec Hours.LowNib,":"
Debug Dec Minutes.HighNib, Dec Minutes.LowNib,":"
Debug Dec Seconds.HighNib,Dec Seconds.LowNib
Debug" ",DEC Month.HighNib,DEC Month.LowNib,"/"
Debug Dec Date.HighNib,Dec Date.LowNib,"/"
Debug Dec Year.HighNib,Dec Year.LowNib,cr

Actual example display:- 11:09:25 04/11/03


However, when I try to convert the BCD data in the
"Seconds" byte to Decimal so that I can use its
actual decimal value in conditional statements to
time specific actions, the results are unexpected.

The code used to convert the BCD data in the
"Seconds" byte to decimal is as follows:

Secs_In_Dec=((Seconds&$F0)>>4*10)+(Seconds&$0F)

The result, when debugged with the following
statement:
"Debug dec Secs_In_Dec,cr"
counts in decimal to 59 and then jumps to 09, 19, 29,
up to 99. The count then carries on with 10 11,
12, up to 59.

Interestingly, when I debug in binary as follows:
"Debug bin8 Secs_In_Dec,cr" I get what one would
expect: 00000000 then 00000001 as the Main Debug
screen shows the seconds count going from 59 to 00

I am overlooking something fundamental here but
cannot figure out what it is.

I would welcome illumination...

Sean

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-11 17:49
    >The register data (in BCD) from a Dallas 1302 RTC,
    >displays nicely on a BS2 Debug screen with the
    >following code:
    >
    >'Display RTC Time and Date
    >Debug Home,Dec Hours.HighNib,Dec Hours.LowNib,":"
    >Debug Dec Minutes.HighNib, Dec Minutes.LowNib,":"


    You can do that more easily with
    Debug hex2 Minutes,":"

    etc. BCD and HEX are identical for numbers using only digits 0--9.


    >Debug Dec Seconds.HighNib,Dec Seconds.LowNib
    >Debug" ",DEC Month.HighNib,DEC Month.LowNib,"/"
    >Debug Dec Date.HighNib,Dec Date.LowNib,"/"
    >Debug Dec Year.HighNib,Dec Year.LowNib,cr
    >
    >Actual example display:- 11:09:25 04/11/03
    >
    >
    >However, when I try to convert the BCD data in the
    >"Seconds" byte to Decimal so that I can use its
    >actual decimal value in conditional statements to
    >time specific actions, the results are unexpected.
    >
    >The code used to convert the BCD data in the
    >"Seconds" byte to decimal is as follows:
    >
    >Secs_In_Dec=((Seconds&$F0)>>4*10)+(Seconds&$0F)

    That looks okay, but you can also use this..
    Secs_In_Dec = Seconds.nib1 * 10 + Seconds.nib0


    >
    >The result, when debugged with the following
    >statement:
    > "Debug dec Secs_In_Dec,cr"
    >counts in decimal to 59 and then jumps to 09, 19, 29,
    >up to 99. The count then carries on with 10 11,
    >12, up to 59.
    >
    >Interestingly, when I debug in binary as follows:
    >"Debug bin8 Secs_In_Dec,cr" I get what one would
    >expect: 00000000 then 00000001 as the Main Debug
    >screen shows the seconds count going from 59 to 00

    You need to use DEC2, not DEC. What you are seeing is the ghost of
    the 9 left on the screen from the "59", as the Stamp DEC sends out
    single digits "0", "1" ...

    -- Tracy



    >
    >I am overlooking something fundamental here but
    >cannot figure out what it is.
    >
    >I would welcome illumination...
    >
    >Sean
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-11 19:18
    Tracy
    Thank you .
    It works perfectly now.
    I am very grateful for your help.
    Sean

    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, April 11, 2003 12:49 PM
    Subject: Re: [noparse][[/noparse]basicstamps] BCD -> Dec


    | >The register data (in BCD) from a Dallas 1302 RTC,
    | >displays nicely on a BS2 Debug screen with the
    | >following code:
    | >
    | >'Display RTC Time and Date
    | >Debug Home,Dec Hours.HighNib,Dec Hours.LowNib,":"
    | >Debug Dec Minutes.HighNib, Dec Minutes.LowNib,":"
    |
    |
    | You can do that more easily with
    | Debug hex2 Minutes,":"
    |
    | etc. BCD and HEX are identical for numbers using
    only digits 0--9.
    |
    |
    | >Debug Dec Seconds.HighNib,Dec Seconds.LowNib
    | >Debug" ",DEC Month.HighNib,DEC Month.LowNib,"/"
    | >Debug Dec Date.HighNib,Dec Date.LowNib,"/"
    | >Debug Dec Year.HighNib,Dec Year.LowNib,cr
    | >
    | >Actual example display:- 11:09:25 04/11/03
    | >
    | >
    | >However, when I try to convert the BCD data in the
    | >"Seconds" byte to Decimal so that I can use its
    | >actual decimal value in conditional statements to
    | >time specific actions, the results are unexpected.
    | >
    | >The code used to convert the BCD data in the
    | >"Seconds" byte to decimal is as follows:
    | >
    | >Secs_In_Dec=((Seconds&$F0)>>4*10)+(Seconds&$0F)
    |
    | That looks okay, but you can also use this..
    | Secs_In_Dec = Seconds.nib1 * 10 + Seconds.nib0
    |
    |
    | >
    | >The result, when debugged with the following
    | >statement:
    | > "Debug dec Secs_In_Dec,cr"
    | >counts in decimal to 59 and then jumps to 09, 19,
    29,
    | >up to 99. The count then carries on with 10 11,
    | >12, up to 59.
    | >
    | >Interestingly, when I debug in binary as follows:
    | >"Debug bin8 Secs_In_Dec,cr" I get what one would
    | >expect: 00000000 then 00000001 as the Main Debug
    | >screen shows the seconds count going from 59 to 00
    |
    | You need to use DEC2, not DEC. What you are seeing
    is the ghost of
    | the 9 left on the screen from the "59", as the Stamp
    DEC sends out
    | single digits "0", "1" ...
    |
    | -- Tracy
    |
    |
    |
    | >
    | >I am overlooking something fundamental here but
    | >cannot figure out what it is.
    | >
    | >I would welcome illumination...
    | >
    | >Sean
    |
    |
    | 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.