How do we OR two bits in ATxmega128

inputoutputprogrammingsensor

I am working with ATxMega128 and programming it in C.

I have two inputs coming from a sensor and I want to turn on an LED when I get output from either of the sensor.

I can blink my LED if i get output from both of my sensor (i.e. I can do ANDING using &) but I do not know how to do ORRING. (Just need the syntax)

One way i can think of is to write two separate if statements taking one sensor at a time but I want to write a single if loop.

Can you please help me out?

Thanks.

Best Answer

For OR you use the pipe symbol:

|

This is a vertical bar, usually the symbol is close to the enter key on the keyboard;

For example: int x = BIT0 | BIT 1;

However, seeing as you're asking rather basic questions, I recommend that you find a tutorial or book to cover this. K&R which is the C book covers this. I myself have written a tutorial (aimed at MSP430 but covering many general aspects) here.

Related Topic