Shop OBEX P1 Docs P2 Docs Learn Events
repost of the repost, I don''t know what went wrong....Clock Help — Parallax Forums

repost of the repost, I don''t know what went wrong....Clock Help

ArchiverArchiver Posts: 46,084
edited 2003-01-06 19:24 in General Discussion
>hours = 18
>minutes = 45
>day = 7 'entered these for testing the routine
>SEROUT 7\8, 16468, [noparse][[/noparse]hex hours,hex minutes,hex day] ' Send the time set info
>to the table.
>This won't work.
>...
>I tried this out to see whether it would work and it worked fine.
>SEROUT 7\8, 16468, [noparse][[/noparse]$16,$45,$1] ' Send the time set info to the
>table.


Try this:

hours=$18
minutes=$45
day=$07

It has to be HEX (=BCD), with the $ prefix.

It is a good idea to understand the different computer number
systems. HEX can hold 256 different values in one byte, from $00 to
$FF. BCD is like HEX, except that the two digits as shown as HEX can
only take values from $0 to $9, not the letters $A to $F.

There is a big difference between
hours=18
and
hours=$18.
In different notations, the first one is
hours=18 in decimal, %00010010 in binary, $12 in hex. That $12 is
the hex value being sent by the serout command in your first example,
and $12 is not what you want.
You want,
hours=$18 in hex, %00011000 in binary, 24 in decimal.
Notice that the two nibbles of $18 are $1 and $8. The high nibble
has a positional value of 16, so to convert $18 to decimal, you have
to use this formula:
1*16 + 8 = 24 the decimal value of $18.

It will help your programming a lot if you understand these number
systems. Scott Edwards' book has a good introduction to this, as do
some of the Stamps-in-Class texts, and I bet you that Al Williams has
a good tutorial on it on line as well.

I hope that helps,
-- Tracy


On the other hand, to convert decimal hours=18 to hex, you come out
with $12 in hex, and that is not what you want when you set your
clock.
Sign In or Register to comment.