PDA

View Full Version : Displaying a decimal larger than 255 on LCD?



djmachine
- 8th March 2009, 17:47
Hello. Exactly as the title states.. how do I display a decimal larger than 255? I am storing a count in two bytes in an array and would like to display the 2 bytes as a decimal on the LCD which can be 0 - 65535?

Thanks!

Chris Barron
- 8th March 2009, 18:12
Hello. Exactly as the title states.. how do I display a decimal larger than 255? I am storing a count in two bytes in an array and would like to display the 2 bytes as a decimal on the LCD which can be 0 - 65535?

Thanks!


Assuming using LCDOUT, and array elements are var[0] and var[1]

dec var[1] dig 2, dec var[1], dig 1, dec var[1] dig 0, dec var[0] dig 2, dec var[0] dig 1, dec var[0] dig 0

Might need a bit of a tweak, basically use the extension 'dig' to point to the digit of the 3-digit variable you wish to display. This will also display leading zeros

Chris Barron
- 8th March 2009, 20:27
Assuming using LCDOUT, and array elements are var[0] and var[1]

dec var[1] dig 2, dec var[1], dig 1, dec var[1] dig 0, dec var[0] dig 2, dec var[0] dig 1, dec var[0] dig 0

Might need a bit of a tweak, basically use the extension 'dig' to point to the digit of the 3-digit variable you wish to display. This will also display leading zeros


Deliberate mistake ;-).
Var[0] can only hold up to 255 so as it stands it may not be quite correct to adopt that technique.

What is the largest number you are using in each byte ? Does the lower byte count right up to 255 and then roll over, at the same time incrementing the higher byte ? Or, do you restrict the range of the lower byte to some other amount, such as 99 ?

If you can't jump directly to extracting the values you need using the 'dig' directive, then you can always write a short math routing to count off the two bytes.

sum var word
lower var byte
upper var byte

sum = (upper * 255) + lower

lcdout dec sum dig 4, dec sum dig 3, dec sum dig 2, dec sum dig 1 , dec sum dig 0

aratti
- 8th March 2009, 21:39
sum = (upper * 255) + lower

Should be:

sum = (upper * 256) + lower

Al.

timmers
- 8th March 2009, 22:43
Could it not be as simple as:-

COUNTER VAR WORD
COUNTER_H VAR COUNTER.BYTE1 'high byte
COUNTER_L VAR COUNTER.BYTE0 'low byte

LCDOUT $FE,128,DEC4 COUNTER 'top row, position 1.

Tim.

Chris Barron
- 9th March 2009, 20:07
Could it not be as simple as:-

COUNTER VAR WORD
COUNTER_H VAR COUNTER.BYTE1 'high byte
COUNTER_L VAR COUNTER.BYTE0 'low byte

LCDOUT $FE,128,DEC4 COUNTER 'top row, position 1.

Tim.

I don't think so, because although the LCDOUT is very simple and elegant, the maximum number which can be stored in either Counter_H or Counter_L is 255. Therefore the largest value which the word sized variable Counter can be is 255255.

There needs to be a conversion first. The high byte needs to be multiplied by 256 (not 255 as I originally pointed out) and then added to the low byte before it gets stored in the word 'Counter'

timmers
- 9th March 2009, 23:01
Indeed you are right.

Without knowing the exact task, I just wanted to keep it simple...

djmachine
- 10th March 2009, 02:06
I need to be able to count to around 2000 without rolling over so 2 bytes would be plenty. I tried the code you posted.. but it still rolled over at 255. hmmm....

Byte_Butcher
- 10th March 2009, 02:39
Hello. Exactly as the title states.. how do I display a decimal larger than 255? I am storing a count in two bytes in an array and would like to display the 2 bytes as a decimal on the LCD which can be 0 - 65535?

Thanks!


how about:


MyWord = LowByte + HighByte << 8 ' Multiply HighByte by 256 (left shift 8) and add LowByte

LCDOUT $fe,$1, MyWord

Aratti had it right in post #4 I think, except I did it with leftshift instead of multiply by 256. Same thing...


Steve

Chris Barron
- 10th March 2009, 08:27
I need to be able to count to around 2000 without rolling over so 2 bytes would be plenty. I tried the code you posted.. but it still rolled over at 255. hmmm....

It still rolls at 255 ? Did yoiu declare the destination variable as a word or a byte ?

Ever count of 1 of the lower byte equates to 1 in the destination variable, and every count of 1 in the high byte equates to 256 in the destination variable.

2000, in this scheme, consists of highbyte = 7, low byte = 208

As you can see, you need to multiply whatever is in the highbyte by 256. In this case 256*7 = 1792. Then add the lowbyte directly, and 1792 + 208 = 2000

Acetronics2
- 10th March 2009, 09:02
Could it not be as simple as:-

COUNTER VAR WORD
COUNTER_H VAR COUNTER.BYTE1 'high byte
COUNTER_L VAR COUNTER.BYTE0 'low byte

LCDOUT $FE,128,DEC4 COUNTER 'top row, position 1.

Tim.

Hi, You were not so far ...




COUNTER VAR WORD

COUNTER.Highbyte = EEPROM_READ1 'high byte ( note: EEPROM_READ1 or value1, or ...xxx1)
COUNTER.Lowbyte = EEPROM_READ2 'low byte

LCDOUT $FE,128,DEC4 COUNTER 'top row, position 1.


No multiplying necessary ...

Alain