need help configuring port to input in 8051

Posted by Aabid Ali on Stack Overflow See other posts from Stack Overflow or by Aabid Ali
Published on 2010-05-07T18:24:20Z Indexed on 2010/05/07 18:28 UTC
Read the original article Hit count: 301

Filed under:

The connection is as follows An infrared sensor circuit which yields 0 or 5v depending on closed or open circuit output line to port 2_0 pin of microcontroller 8051 philips.Problem is when i do this the circuit value are overridden by the current value on port 2_0 led always goes on.Here is my code(in keil c) i guess i have not configured P 2_0 as input properly

void MSDelay(unsigned int);

sbit led=P1^0;

void main()
{
    unsigned int var;
    P2=0xFF;
    TMOD=0x20;
    TH1=0xFD;
    SCON =0x50;
    TR1=1;

    while(1)
    {
        var=P2^0;
        if(var==0)
        {  
            led=1;
            SBUF='0';
            while(TI==0);
                TI=0;
            MSDelay(250);
        } 
        else
        {   
            led=0;
            SBUF='9';
            while(TI==0);
                TI=0;
            MSDelay(100);
        }
    }       
}

© Stack Overflow or respective owner

Related posts about c