c syntax for PIC's

foTONICS

Sep 30, 2011
332
So I was reading through "Gooligum's" website and he uses these commands:

sGPIO |= 1<<1; // turn on LED on GP1
sGPIO &= ~(1<<1); //turn off LED on GP1
sGPIO ^= 1<<2; //toggle LED on GP2 using shadow reg

Now I understand everything but the "|=" and the "&=". Could anyone shed some light on this?

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,540
These are compound operators meaning:

a |= x is equivalent to a = a | x
a &= x is equivalent to a = a & x.
etc.

The effect is:
- apply the logic operation
- write back the result to sGPIO

This is common C syntax, not a special for PICs.

foTONICS

Sep 30, 2011
332
ooooooh sorta like:

a += b is the same as a=a+b

thanks a lot!

Replies
2
Views
1K
Replies
4
Views
1K
B
Replies
27
Views
3K
Jasen Betts
J
Z
Replies
4
Views
2K
Z