PDA

View Full Version : Help with some maths please



financecatalyst
- 29th January 2014, 01:39
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.



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

AvionicsMaster1
- 29th January 2014, 03:02
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.

Darrel Taylor
- 29th January 2014, 05:15
I would skip the modulus stuff, and go for the MidWord Multiplier (*/), which has an implied /256.



Value VAR WORD
Temp VAR WORD

Value = 502

Temp = Value */ 100
LCDOUT DEC Temp/100,".",DEC2 Temp," "

financecatalyst
- 29th January 2014, 13:50
Thanks a lot. Problem solved (for now).

I'll be BACK!