Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI

Status
Not open for further replies.

best4n

Newbie
Newbie level 2
Joined
Jan 31, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,297
int s;

Code C - [expand]
1
2
3
4
5
6
7
if (s & 8)
       OUTPUT_HIGH(PIN_A3);
   else 
       OUTPUT_HIGH(PIN_A2);
delay_ms(1);
OUTPUT_LOW (PIN_A2);
OUTPUT_LOW (PIN_A3);



I was going through part of a PIC code i downloaded using the CCS compiler, plz can someone explain to me the meaning of " if (s & 8)" , s was declared as an integer, plz i would be anticipating help soonest, thanks in advance.
 
Last edited by a moderator:

Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI

It's a simple bit-and operation - look up C boolean operators.

This one tests if bit 3 of variable s is high. If it is high, then the operation (s & 8) evaluates as true for the if statement
 

Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI

Hello Mr FoxyRick, thanks a lot, plz can you show me any link where this issue was handled, coz i'm still not clear with the roll of the '8' used in the code and not bit '3' as u said, also i've gone through CCS programming manual
and still could not find any similar example . once more thanks a lot
 

Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI

You may not find this in CCS programming manual. This is just C code. Search the internet for Bitwise operations in C.

8 in binary is equal to 00001000. So it is the bit 3 which is one and all other bits are zero. When this 8 (00001000) is bitwise AND (&) with any number.The result will be zero (False) except for the numbers which has its bit # 3 is set (high).

In other words, this operation is basically testing the variable s for bit #3 for high (1). If true, the output A3 is High for 1ms otherwise A2 is high for 1ms.
 

Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI

Code:
if(s&8)
in this, assume a switch is connected to 3rd bit of the PORT.
By this condition we are checking, whether the switch is pressed or not.

If the switch is pressed, s becomes 0001000 and binary value of 8 is 00001000. Bitwise AND(&) operation of these two numbers will true ,then PIN_A3 will be high, otherwise the value becomes false and the PINA_3 will be LOW.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top