If I have data coming in PORTC.7 and I want to Invert it and send it out PORTC.0
Whats the best way if I just XOR it it errors
PORTC.0 XOR PORTC.7
Thanks
Inverting port pin
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
I think you need a destination in there somewhere. To toggle a bit you XOR it with '1'
Here's a few choices...
The first one may cause problems in that it always sets the output pin (and then clears it if needed). Not a good choice.
The fastest method is the third
Here's a few choices...
Code: Select all
// 9 instructions
// note: this always sets PORTC.0 first no matter what, so it may glitch the output
PORTC.0 = PORTC.7 xor 1
// 7 instructions
PORTC.0 = not PORTC.7
// 5 instructions
if (PORTC.7 = 1) then
PORTC.0 = 0
else
PORTC.0 = 1
endif
The fastest method is the third