Shop OBEX P1 Docs P2 Docs Learn Events
SERIN question2 — Parallax Forums

SERIN question2

ArchiverArchiver Posts: 46,084
edited 2004-05-10 16:58 in General Discussion
I've another question about the SERIN command.
I saw an example that the baudmode of SERIN command is expressed in
Hex number, likes the following:
SERIN 16, 84+$4000, [noparse][[/noparse]char]
Is it the same as (SERIN 16, 16648, [noparse][[/noparse]char]) ?
What is the advantage of using Hex number?
Thanks all!!

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-05-10 16:35
    The actual number used is a combination of
    several 'hex' value. Keeping them in 'hex'
    clearly indicates your intent.

    $8000 == Open Baud Mode.
    $4000 == Inverted Polarity
    $2000 == 7-bit, Even parity (0 is 8-bit no)

    84 == 9600 baud select value.

    So, for 9600 inverted, 8 data, not Open,
    you would have ($4000 + 84) for your baud mode.
    I would typically define a constant for this:
    I9600 CON $4000 + 84

    and then use it as:
    SEROUT 16, I9600, [noparse][[/noparse]MyData,13]

    --- In basicstamps@yahoogroups.com, "ck1_chu" <ck1_chu@y...> wrote:
    > I've another question about the SERIN command.
    > I saw an example that the baudmode of SERIN command is expressed in
    > Hex number, likes the following:
    > SERIN 16, 84+$4000, [noparse][[/noparse]char]
    > Is it the same as (SERIN 16, 16648, [noparse][[/noparse]char]) ?
    > What is the advantage of using Hex number?
    > Thanks all!!
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-10 16:58
    It is simply a matter of convenience, as the HEX value shows the baud
    rate "84" separate from the mode "$4000". The baud rate can be a
    value from 0 up to 8191, which is the same as HEX $0 to $1fff. That
    takes 13 bits, and leaves 3 bits at the top. Those three bits are
    the mode bits:
    +$2000 for 7 bit , even parity
    +$4000 for inverted polarity (serial line rests at low level,
    logical 1 is low level)
    and (SEROUT only)
    +$8000 open mode (only one polarity actively driven)

    So when you have a baudmode written as $4000+$54, it is easy to see
    what's what. But inside the stamp that is stored exactly the same as
    is 16468 (but not 16648 as in your example below, which proves the
    point) . It makes it easy to spot errors, for example, if you are
    using a BS2p, then 9600 baud is $f0, so the baudmode is
    $4000 + $f0 = $40f0 or 16624

    -- Tracy


    >I've another question about the SERIN command.
    >I saw an example that the baudmode of SERIN command is expressed in
    >Hex number, likes the following:
    >SERIN 16, 84+$4000, [noparse][[/noparse]char]
    >Is it the same as (SERIN 16, 16648, [noparse][[/noparse]char]) ?
    >What is the advantage of using Hex number?
    >Thanks all!!
Sign In or Register to comment.