Exclusive bit settings (i.e. PORTS)


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938

    Default Exclusive bit settings (i.e. PORTS)

    Hello,

    I want to set exclusively 3 bits on a PORT.

    Let's say I have PORTB = %10011001 and want to set ONLY the three LSB.

    I can use PORTB = PORTB | 7, I get %1001111 and this is fine.

    How do I do if I want to change from %10011001 to %00001001?
    Roger

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Hello,
    I want to set exclusively 3 bits on a PORT.
    Let's say I have PORTB = %10011001 and want to set ONLY the three LSB.
    I can use PORTB = PORTB | 7, I get %1001111 and this is fine.
    How do I do if I want to change from %10011001 to %00001001?
    PortB = PortB & %00001111
    AND function
    keeps the lower four bits, dumps the upper four, but that's only one case of bit changing. If you want to be able to change any bits at any time while retaining others, it's going to take more than one step.

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help.

    I'm not used yet with these operators.

    Gone a have some trials...
    Roger

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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