Setting bits


Closed Thread
Results 1 to 10 of 10

Thread: Setting bits

Hybrid View

  1. #1
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    Ok, I kind of see where your going. What I need to do is something very similar. If I understand correctly DCD will set the specified bit. Here is what the help in MCS says:

    "DCD returns the decoded value of a bit number. It changes a bit number (0 - 15) into a binary number with only that bit set to 1. All other bits are set to 0.

    Example

    B0 = DCD 2 ' Sets B0 to %00000100"

    Ok, thats cool. And after re-reading that other thread I see where your going with this. Lets say I know my bargraph needs to display 50% or 8 segments. I would need to say something like DCD = 8. This gives me %10000000. So in effect only my 8th LED will light up. My problem is I need ALL the LED's from 1 to 8 to light up... what I need to see is %11111111.

    Using ~DCD is ALMOST what I need. For the number 8 I would now have 011111111. Close but not quite. Just for fun, lets say that I really need only 4 led's lit up. (%00001111). Using ~DCD I would actually get %11110111). Do I understand this correctly?

    Anyway, now that I have actually had some sleep. I can think a wee bit more clearly. Using the look up table should work, just seems there should be an easier way to do this. For anyone following along I figured out my final formulat. I will need three peices of information: Bargraph upper bound, Bargraph lower bound, and value. (And yes, I have spent WAY too many years messing around with arrays in VB ).

    Here is my final formula then:

    Bargraph = (Data - LowBound) / ((highbound - lowbound)/16)

    Simplest samples to plug in with oil pressure values: Upper is 32, lower is 0. For a presure of 16 (50% on the bargraph) I need to light 8 led's

    Bargraph = (16 - 0)/((32 - 0)/16)
    bargraph = 16/2 = 8.

    So now I just need to tell the pic to light up LED's 1-8 and I am done. Until I get a better lightbulb over my head, Im just using a look up table. then of course, there will be the issue of getting the values IN to the processor.. but thats a whole other war to battle.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    971


    Did you find this post helpful? Yes | No

    Default

    I think you wish to build a bar graph with a value

    This will help you

    Code:
    ' Build a bar from the value in ChPeak
    ' Each led gets 1 bit - 0 for on, 1 for off
    ' Output in BarGraph 16 bits
    ' Gr[0] is a temporary variable
    '
    BuildBar:
        for gr[0] = 0 to 15
          if gr[0] < ChPeak then
            ' put this LED off 1
            BarGraph.0(gr[0])=1
          else
            ' put this LED on 0
            BarGraph.0(gr[0])=0
          endif
        next
        return

  3. #3
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    Well that certainly would work as well. Thanks. I was hoping there would be some kind of command like DCD that would just magicaly set all the bits on but I guess not. I might look into just manipulating the bits some how. then again, I havnt looked but how many CPU cycles does the lookup command take? anyone know?

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


    Did you find this post helpful? Yes | No

    Default

    No magic commands, but maybe this will do ...
    BarGraph is a Word var.

    Code:
    BarGraph=$FFFF<<(LEDcount-((BarData-RangeLOW)*LEDcount)/(RangeHIGH-RangeLOW))
    If the BAR is going the wrong way, just change it to shift right (>>).
    Last edited by Darrel Taylor; - 26th November 2009 at 21:02. Reason: >>
    DT

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    971


    Did you find this post helpful? Yes | No

    Default

    Wow Darell, that's an ace. I use this for scaling readings but never thought of it this way. Nice tip.

    Superb

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Jerson,

    bearpawz had most of it already, I just filled in the blanks.
    Then compiled, tested and heard ... Ohhh Yeeaaah, before I realized it was me talking.
    DT

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Configuration bits setting problem
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th August 2009, 18:25
  3. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 15:01
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15:31
  5. Trouble setting config. bits
    By jswayze in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th March 2004, 23:22

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