XOR single bit???

Status
Not open for further replies.

DMon3y141

New Member
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?
 
Read the entire port, AND it with the mask you want, then XOR it with the mask, finally OR it back to the port.
 
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??
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…