PDA

View Full Version : Displaying numbers



Christopher4187
- 19th March 2006, 18:51
Hi,

In part of my code I am using variables b1, b2 and b3. What I am trying to do is this:

b1=1
b2=3
b3=5

tach=b1,b2,b3

When I go to complile it, it keeps giving me an error.

Can anyone help me with this?

Thanks,

Chris

Archilochus
- 19th March 2006, 19:31
I'm guessing that in this example you want 'tach' to end up being 135?

So you'd want b1 to be the 100's place of tach, b2 to be the 10's place, and b3 to be the 1's place, is that correct?

Christopher4187
- 20th March 2006, 00:50
Yes, that is correct. When I display it to a LCD display, this works correctly when I use the DEC command. I have tried everything and still can't get it.

keithdoxey
- 20th March 2006, 08:28
How about

tach = (b1*100)+(b2*10)+b3


Why are you speciying the digits individually ?

Whats wrong with....

tach = 135 'or whatever

LCDout DEC tach ' which would suppress leading zeros eg 135 or 79 or 4

LCDout DEC3 tach ' which would always display 3 digits. eg 135 or 079 or 004

Christopher4187
- 20th March 2006, 10:24
Thanks for the reply. I never thought of doing tach = (b1*100)+(b2*10)+b3 and this will work perfect! The problem is that the numbers are coming over a wireless link and I am having trouble sending word variables. I know these are byte variables but it is only an example. Anyhow, the variables are not going to an LCD display. This is a great temporary solution until I can find out how to send word variables over a wireless link.

Thanks!

Archilochus
- 20th March 2006, 14:01
Be sure not to overflow your variable type with the calculation
tach = (b1*100)+(b2*10)+b3

Arch

Melanie
- 20th March 2006, 15:50
Arch... it would not be possible to overflow a word with that formula...

Archilochus
- 20th March 2006, 16:59
Arch... it would not be possible to overflow a word with that formula...

Guess I should have been more specific about that - I meant if he was using a byte variable. (but now I see that he mentioned a word-sized variable - DUH!)

Arch

DynamoBen
- 20th March 2006, 23:14
"This is a great temporary solution until I can find out how to send word variables over a wireless link."

If you can send bytes then you can send words.

When you send just break the words into bytes.

tach var word

tach.lowbyte = high byte of word
tach.highbyte = low byte of word