Help with some maths please


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default 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
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default 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.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default 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," "
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Help with some maths please

    Thanks a lot. Problem solved (for now).

    I'll be BACK!
    ___________________
    WHY things get boring when they work just fine?

Similar Threads

  1. Maths help please
    By Tina10 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th June 2012, 17:45
  2. Maths problem anyone ?...
    By Bonxy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 17th September 2011, 23:24
  3. PBPro Maths Help
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th June 2011, 06:38
  4. PbPro Maths Help
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 28th October 2010, 23:50
  5. Maths again...
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st September 2010, 23:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts