There are a number of ways that you can go about doing this, but lets say that you wanted to read some data in from PORTB and then you wanted all of that data to get inverted, you would have a variable set up called something like PORTB_INVERTED and then you would have this piece of code:
Code: Select all
movf PORTB, w
xorlw b'11111111'
movwf PORTB_INVERTED
If you are not up to speed with how an xor gate works then here is the truth table:
So what we do here is we xor two bits at a time, top and bottom.
so lets say that we had 01001101 coming in on portb and we xored it, we would have this:
01001101
11111111
-----------
10110010
If you only wanted to invert the very first bit, then you just need to change all other bits when xoring to logic 0's, like this:
Code: Select all
movf PORTB, w
xorlw b'00000001'
movwf PORTB_INVERTED
01001101
00000001
-----------
01001100
Hope that was a handy hint!