Maker Pro
Maker Pro

c syntax for PIC's

foTONICS

Sep 30, 2011
332
Joined
Sep 30, 2011
Messages
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?

Thanks in advance!
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,540
Joined
Nov 17, 2011
Messages
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:
- read sGPIO
- 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
Joined
Sep 30, 2011
Messages
332
ooooooh sorta like:

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

thanks a lot!
 
Top