Rounding Word Values


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    This is perfect.... I get more out of these discussions then any one book I own.

    Thanks Al

    Chris

    btw

    The circuit I am working on is for measuring the amount of salt in my water softener brine tank and displays the level on a blank switch plate via 8 LED's (see attachment). The circuit uses a Parallax PING sensor, 16F87 for the slave and 16F876 for the master. communication is via RS-485.

    If anyone is interested in the specifics, I would be more than happy to share details.

    Again, thanks for all the help.

    Chris
    Attached Images Attached Images  

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Chris, I made a mistake! Sometimes I forget that PBP is not VB and in this case I have use the power sign^ improperly since PBP is not able to do power (the sign is used for Bitwise Exclusive OR). So the code I have posted will not work! To overcome this limitation I have used a lookup table so the working code is as follow:

    Code:
    AA0  var Byte  ' new variable to add.
    BB0  var byte  ' new variable to add
    
    If Percent < 95 then
    AA0 = (Percent / 10) - 1
    LOOKUP2 AA0,[1,3,7,15,31,63,127,255],BB0
    PortB = BB0
    else
    PORTB = %11111111
    FreqOut bz, 250, 4000
    pause 250
    PORTB = %01111111
    Low bz
    pause 250
    endif

    As you can see the code didn't change much, just removed (2^AA0)-1 and added a new variable.


    Al.
    Last edited by aratti; - 28th March 2010 at 18:47.
    All progress began with an idea

  3. #3
    Join Date
    Mar 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Al, I appreciate the correction. I understood what you where trying to do. I too am more familiar with VB than PBP.
    This definitely simplifies the overall code.
    Thank you very much.

    Chris

Members who have read this thread : 0

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