Help converting word into 5 seperate bytes for LCD display
Archiver
Posts: 46,084
I was wondering if anyone had a snippet of code for use with a BS1
that could convert a word into 5 seperate bytes (65,532). For
example, if the value was 65,532 (all ones in binary) i'd like to
convert the word to 5 bytes each containing 6,5,5,3,and 2. I'm
setting up a datalogger and want to send some values to an Async LCD
for display. I can get the values into the stamp fine but am having
trouble finding a way to send them to the LCD. Any help would be
appreciated,
Mark
that could convert a word into 5 seperate bytes (65,532). For
example, if the value was 65,532 (all ones in binary) i'd like to
convert the word to 5 bytes each containing 6,5,5,3,and 2. I'm
setting up a datalogger and want to send some values to an Async LCD
for display. I can get the values into the stamp fine but am having
trouble finding a way to send them to the LCD. Any help would be
appreciated,
Mark
Comments
yourself when you look in the book. I don't have the page number in
the new manual (244 in the 1.8 manual) but look for the DIG operator,
in the section on binary Operators. It very nicely returns the
specified decimal digit of a 16 bit value. Sometimes it seems they
though of everything.
Mike
>I was wondering if anyone had a snippet of code for use with a BS1
>that could convert a word into 5 seperate bytes (65,532). For
>example, if the value was 65,532 (all ones in binary) i'd like to
>convert the word to 5 bytes each containing 6,5,5,3,and 2. I'm
>setting up a datalogger and want to send some values to an Async LCD
>for display. I can get the values into the stamp fine but am having
>trouble finding a way to send them to the LCD. Any help would be
>appreciated,
>Mark
>
>
>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/
course).
If you want to convert to BCD, you could use code like this (untested):
Ddigit = 10000
Loop:
digit = val/Ddigit
val = val - digit * Ddigit
gosub write_LCD_digit ' send digit to LCD
Ddigit=Ddigit/10
if Ddigit<>0 then Loop
' Done
Val is the value you want to break apart (we destroy it too). The digit
variable is the output digit (a nibble is fine here). This works because
of integer math. The only downside is initial zeros print out. You can
surpress those, but you have to be careful for the "zero" case. So
something like:
Ddigit = 10000
LeadDigit = 0
Loop:
digit = val/Ddigit
if LeadDigit=1 then dispdig
if digit=0 AND Ddigit<>1 then Nodisp
Dispdig:
val = val - digit * Ddigit
LeadDigit=1
gosub write_LCD_digit ' send digit to LCD
Nodisp:
Ddigit=Ddigit/10
if Ddigit<>0 then Loop
' Done
I think that would work. The idea is to skip 0 digits until you either
get some digit printed, or until you are in the 1 position. So for 00500
you want to surpress the first 2 zero's but not the last 2. For 0, you
want a 0 to print.
Al Williams
AWC
* Floating point A/D
http://www.al-williams.com/awce/pak9.htm
>
Original Message
> From: Mike Davey [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=E1IyRmFCS0nSmkBpDOwVMLJimajtYVO8QFi2buVf0nXSWzTgBDbciSbJ0OwamNyRsHQBRtvfNNoU3gtp]mdavey@n...[/url
> Sent: Tuesday, January 01, 2002 4:29 PM
> To: basicstamps@yahoogroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Help converting word into 5
> seperate bytes for LCD display
>
>
> While I don't have any code handy, it's really simple and you'll kick
> yourself when you look in the book. I don't have the page number in
> the new manual (244 in the 1.8 manual) but look for the DIG operator,
> in the section on binary Operators. It very nicely returns the
> specified decimal digit of a 16 bit value. Sometimes it seems they
> though of everything.
>
> Mike
>
>
> >I was wondering if anyone had a snippet of code for use with
> a BS1 that
> >could convert a word into 5 seperate bytes (65,532). For example, if
> >the value was 65,532 (all ones in binary) i'd like to
> convert the word
> >to 5 bytes each containing 6,5,5,3,and 2. I'm setting up a
> datalogger
> >and want to send some values to an Async LCD for display. I
> can get the
> >values into the stamp fine but am having trouble finding a
> way to send
> >them to the LCD. Any help would be appreciated,
> >Mark
> >
> >
> >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/
>
The BS1 does not use the DIG instruction but if it did this would be
a clean solution, however I thnk I can use Al's idea to put something
together. Either way thanks both for your help.
Mark
Just from memory, I don't think the BS1 does DIG (the BS2s do, of
course).
If you want to convert to BCD, you could use code like this
(untested):
Ddigit = 10000
Loop:
digit = val/Ddigit
val = val - digit * Ddigit
gosub write_LCD_digit ' send digit to LCD
Ddigit=Ddigit/10
if Ddigit<>0 then Loop
' Done
Val is the value you want to break apart (we destroy it too). The
digit
variable is the output digit (a nibble is fine here). This works
because
of integer math. The only downside is initial zeros print out. You
can
surpress those, but you have to be careful for the "zero" case. So
something like:
Ddigit = 10000
LeadDigit = 0
Loop:
digit = val/Ddigit
if LeadDigit=1 then dispdig
if digit=0 AND Ddigit<>1 then Nodisp
Dispdig:
val = val - digit * Ddigit
LeadDigit=1
gosub write_LCD_digit ' send digit to LCD
Nodisp:
Ddigit=Ddigit/10
if Ddigit<>0 then Loop
' Done
I think that would work. The idea is to skip 0 digits until you
either
get some digit printed, or until you are in the 1 position. So for
00500
you want to surpress the first 2 zero's but not the last 2. For 0,
you
want a 0 to print.
Al Williams
AWC
* Floating point A/D
http://www.al-williams.com/awce/pak9.htm
Original Message
From: Mike Davey [noparse][[/noparse]mailto:mdavey@n...]
Sent: Tuesday, January 01, 2002 4:29 PM
To: basicstamps@y...
> > Subject: Re: [noparse][[/noparse]basicstamps] Help converting word into 5
> > seperate bytes for LCD display
> >
> >
> > While I don't have any code handy, it's really simple and you'll
kick
> > yourself when you look in the book. I don't have the page number
in
> > the new manual (244 in the 1.8 manual) but look for the DIG
operator,
> > in the section on binary Operators. It very nicely returns the
> > specified decimal digit of a 16 bit value. Sometimes it seems
they
> > though of everything.
> >
> > Mike
> >
> >
> > >I was wondering if anyone had a snippet of code for use with
> > a BS1 that
> > >could convert a word into 5 seperate bytes (65,532). For
example, if
> > >the value was 65,532 (all ones in binary) i'd like to
> > convert the word
> > >to 5 bytes each containing 6,5,5,3,and 2. I'm setting up a
> > datalogger
> > >and want to send some values to an Async LCD for display. I
> > can get the
> > >values into the stamp fine but am having trouble finding a
> > way to send
> > >them to the LCD. Any help would be appreciated,
> > >Mark
> > >
> > >
> > >To UNSUBSCRIBE, just send mail to:
> > > basicstamps-unsubscribe@y...
> > >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@y...
> > 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/
> >