ANDing 3 Conditions using && Operator MikroC PIC

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
3,377
Hello,

i want to use following condition is it true ? i want to AND 3 conditions together..

if (PORTA.F1 == 1 && PIR1.TMR1IF == 1 && FLAG_1 == 1)
{
do something;
}



Thanks
 


Code C - [expand]
1
if ((PORTA.F1 == 1) && (PIR1.TMR1IF == 1) && (FLAG_1 == 1))


tHANKS

I need one more help from you dear

i am trying to increase count = count + 1; using above situation. Everytime above condition is true it should incremenet the value of count = count + 1; means count is incremented on every true of above condition.

i have used code but i am not successful

Code:
if ((PIR1.TMR1IF == 1) && (PORTA.F1 == 1) && (FLAG_1 == 1))
{
COUNT = COUNT + 1;
FLAG_1 = 0;
}

Please help
 

Presumed all variables are binary, you can simplify the expression
Code:
if (PORTA.F1 && PIR1.TMR1IF && FLAG_1)
 

Your code will increment the count every time the test is made while the port bits are high. I assume you want to only count once for each time the condition becomes true. So, you need to have a flag you set when the condition becomes true and cleared when the condition becomes false. Only count when you first detect the condition being true.

Keith
 


Keith you're right

I have implemented that i am successful in that case thanks for suggestion
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…