Help with some maths please
I want to display a few numbers on an 16x4 lcd.
If I have 502, I want to divide it by 256 and display the number in decimal like 1.96
I have created a routine but something is wrong as the display is not showing the correct numbers.
Code:
p1 var byte
p2 var byte
p3 var byte
Value=502
LCDOUT $FE,$90,"Value>",DEC Value
P1=(Value/256) DIG 0
P2=(Value//256) DIG 1
P3=(Value//256) DIG 0
LCDOUT $FE,$80,"Val>",DEC P1,".",DEC P2,DEC P3
The display shows : 502 & 1.46
Re: Help with some maths please
You might try this thread http://www.picbasic.co.uk/forum/showthread.php?t=12480 for an answer on modulus.
Funny, I had to write this down to have it make sense. Using a calculator only confused the issue. Try beginning with smaller numbers is the easiest.
Re: Help with some maths please
I would skip the modulus stuff, and go for the MidWord Multiplier (*/), which has an implied /256.
Code:
Value VAR WORD
Temp VAR WORD
Value = 502
Temp = Value */ 100
LCDOUT DEC Temp/100,".",DEC2 Temp," "
Re: Help with some maths please
Thanks a lot. Problem solved (for now).
I'll be BACK!