This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to give if condition in c in 8051

Actually i m using adc0804 as input to port 1 and and i want to drive motor to another port according to adc input. But the problem is how to give condition in c
Suppose that i have adc output 11001100, and i want to rotate motor to particular angle then i m giving conditio as folows:

if(P1==0xCC)
{
   mmotor1();
}


In this i am not getting motor movement. Plzzz tell me the right if condition.

  • Maybe if the ADC is supposed to represent the angle to be moved too, this is the wrong way to achieve it?

    Perhaps you want to use some math to scale the value on the ADC (based on it's range, etc), to an angle (0..359, whatever)

  • It ain't that easy.

    You have to open the books and do some studying.

    The motor isn't magically going to "jump" to a new angle. If it's a stepper motor, you would normally have to generate a lot of steps to change it from say 10 degrees to 27 degrees. And you need to keep track of time length of these pulses etc.

    So you must figure out which direction to rotate. And how long to rotate. And what steps are needed to get that motor to do such length of rotation. And at what speed it can do that. And during that time, you may still have to look at your input sensor and maybe get a new direction to go.

    Good luck.

  • No program for motor is fine and adc output which is input for port 1 is also giving right output. But when i am giving condition then the motor is not rotating.
    suppose i am getting adc output 11001100 which is input to port1 of 8051 microcontroller.
    I am using the following condition :

     if(P1==0xCC)
    

    Is this condition is valid

  • No program for motor is fine and adc output which is input for port 1 is also giving right output. But when i am giving condition then the motor is not rotating.
    suppose i am getting adc output 11001100 which is input to port1 of 8051 microcontroller.
    I am using the following condition :

     if(P1==0xCC)
    

    Is this condition is valid

  • if( P1 == 0xCC )
    

    As far as 'C' language syntax goes, it is perfectly valid.

    Whether it correctly implements what you're trying to achieve is an entirely different matter!

    You haven't said what specific ship you're using.

    You haven't shown your definition of P1.

    You haven't said what the "magic number" 0xCC is supposed to represent.

    "suppose i am getting adc output 11001100"

    Why "suppose" it? Is it actually happening??

  • there is no matter behind this....this is simple

    if(P1==0XCC)
    { P2^0=1;//POSITIVE TERMINAL OF MOTOR
    P2^1=0;//NEGATIVE TERMINAL OF MOTOR
    }

    plz check your infinite loop.....

    That's all................