How do I check (or set) a group of consecutive bits within a byte?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: How do I check (or set) a group of consecutive bits within a byte?

    Look in your manual under "Logical operators" AND exist. Also you can use &&

    When used as " IF(A and B ) <>= C then take Action" Is a true or false statement.

    Myvariable = %11111111 AND %0000000, this will AND the two variables into myvariable

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: How do I check (or set) a group of consecutive bits within a byte?

    Thanks guys, since the only difference between ADC channel6 & adc channel 7 is 1 bit, I actually I think i've figured a workaround, something like this...

    the code below assumes ADCON0 set as something like 11101 to start with (bit 2-6 set the ADC channel, so this would be ADC channel 7 selected)

    Code:
    if adcon0.2 = 1 then ' if bit 2 is set then ADC Channel must presently be CH7
    adccon.2 =0            ' clear bit 2, to set ADC channel to Channel 6
    else
    adccon0.2 = 1         ' if adcon.2 wasn't set as a '1' then ch6 must have been active therefore now set bit 2 to make AD ch7 active.
    I think that should toggle between ADC ch6 & ch7 on successive calls?
    Last edited by HankMcSpank; - 27th March 2012 at 20:57.

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