BTG equivalent in C18?

Status
Not open for further replies.
What is the C18 equivalent to the assembly instruction BTG (Bit toggle)?
Exclusive OR (^) with a mask of your target bit/byte/word/whatever.

I don't have a PIC example handy, but here's an ARM sample. The code is used to toggle two bits for a piezo beeper to drive it antiphase.
Code:
        IOPIN0 ^= 0x00003000;
 
Last edited:
Both,
LATBbits.LATB7=!LATBbits.LATB7;
and
LATB^=128;
compile to a BTG.

Edit,
Rather shockingly,
LATB=LATB^128;
results in 3 instruction. And that is with full optimization.

Mike.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…