1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

XOR single bit???

Discussion in 'Microcontrollers' started by DMon3y141, Apr 23, 2009.

  1. DMon3y141

    DMon3y141 New Member

    Joined:
    Apr 23, 2009
    Messages:
    2
    Likes:
    0
    Is it possible to XOR a single bit. In theory, this is what I want to do:

    movlw b'00100000' ; moves bit configuration to register W
    xorwf PORTB, f ; xor this value to toggle state of bit 5
    call Delay
    return

    But I do not want to change the values of any other bits besides bit 5. The code above will change the other bits if the bits in PORTB are a 1 (in which some cases they will be).

    I want to just single out bit 5 and XOR that to toggle the state. What is the function to do this?
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,330
    Likes:
    653
    Location:
    Derbyshire, UK
    Read the entire port, AND it with the mask you want, then XOR it with the mask, finally OR it back to the port.
     
  3. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,369
    Likes:
    974
    Location:
    Loveland, CO USA
    I don't see DMon's problem.
    If I XOR any number with b 0010 0000 then I get that number back with bit 5 inverted. All other bits are the same as before. We are not using the same computer??
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. DMon3y141

    DMon3y141 New Member

    Joined:
    Apr 23, 2009
    Messages:
    2
    Likes:
    0

    Yes, ron is right. Once I think about it, XOR with that will not change the status of the other bits. Thank you for helping me resolve my issue.
     

Share This Page