• 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.

BTG equivalent in C18?

Status
Not open for further replies.

futz

Active Member
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:

Pommie

Well-Known Member
Most Helpful Member
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.

Latest threads

EE World Online Articles

Loading
Top