微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 电磁仿真讨论 > How to do if else condition in microC

How to do if else condition in microC

时间:03-31 整理:3721RD 点击:
actually in this program, i want the program to achieve 2 condition(condition 1,condition 2) in order to on a led, condition 1(A == 0) must archive first in order to proceed to condition 2(B == 0), then the led on when both 2 condition achieve .

In this program below, i have a problem with the led will on when (no wander which condition achieve first).

pls help me to do correction in this program
thank

#define A PORTD.F1
#define B PORTD.F2
#define led PORTB.F2

void main()
{
trisd=0xFF;
trisb=0x00;
portd=0xFF;
portb=0x00;

while(1)

{
if (A == 0)
{
if (B == 0)
{
led=1;
}
else
{
led=0;
}
}
else
{
led=0;
}
}
}

Will this work?

Code:
 while(1)
    {
    if((A != 0) && (B != 0)){
      led = 0;
      }

    if((A == 0) && (B != 0))
      {
      while((A == 0) && (B != 0))
        {
        if((A == 0) && (B == 0))
          {
          led = 1;
          break;
          }
        }
      }
    }

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top