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

Reading Pins

Dear All,

I've tried to read the pin of Port1 , but i failed .
I should write one to it right ? , how do i read a one again ?
If i tried to write the following code,it works without checking the status of the pin

Port1_3=1;
if(Port1_3==1)
{
// execute code here ..
// code here executes in the simulator //without checking if the pin is //high or not
}
thanks in advance

Parents
  • " ... its supposed to be ... "

    1st law of programming: the compiler will do what you tell it to do; it will not attempt to second-guess what you actually wanted it to do!!

    So, if you actually write

    sbit P1_3=P1^3;
    
    if ( P1_3==1)
    {
       // execute ...
    }
    does it work?

    As Erik says, "P1_3" is a pretty meaningless name - in a real program, you should certainly choose something that's actually descriptive;eg,
    sbit door_open = P1^3;
    
    if ( door_open )
    {
       // execute ...
    }

Reply
  • " ... its supposed to be ... "

    1st law of programming: the compiler will do what you tell it to do; it will not attempt to second-guess what you actually wanted it to do!!

    So, if you actually write

    sbit P1_3=P1^3;
    
    if ( P1_3==1)
    {
       // execute ...
    }
    does it work?

    As Erik says, "P1_3" is a pretty meaningless name - in a real program, you should certainly choose something that's actually descriptive;eg,
    sbit door_open = P1^3;
    
    if ( door_open )
    {
       // execute ...
    }

Children
No data