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

Read and Write

Hi

Since I want to set three input and one output so

my code would be like that:

//Configurations
sbit READ_1=P1^0;
sbit READ_2=P1^1;
sbit READ_3=P1^2;
sbit SEND=P1^3;

READ_1=1; //INPUT
READ_2=1; //INPUT
READ_3=1; //INPUT
SEND=0; //OUTPUT

//Main program

bit x1,x2,x3;


x1=READ_1;
x2=READ_2;
x3=READ_3;

SEND=x1;

Is it correct?

Arron

Parents
  • #include <Reg52.H>
    sbit show = P1^0;
    sbit sense = P1^1;
    /* .........................................................
    void main (void)
    {
    bit x;
    sense = 1;
    while(1)
    {
    x = sense; // is Pin 1.0 pulled low ?
    show = x; // (re)set Pin 1.1 accordingly
    }
    }
    Is my code right to set sense and show as reading and writing respectively?

    It never can be when you use names that the '51 is incapable of.

    the above is correct for a LED on p1.0 lighting up when p1.1 is pulled low. Of course, that is only true if you have a pullup resistor on p1.1

    Erik

Reply
  • #include <Reg52.H>
    sbit show = P1^0;
    sbit sense = P1^1;
    /* .........................................................
    void main (void)
    {
    bit x;
    sense = 1;
    while(1)
    {
    x = sense; // is Pin 1.0 pulled low ?
    show = x; // (re)set Pin 1.1 accordingly
    }
    }
    Is my code right to set sense and show as reading and writing respectively?

    It never can be when you use names that the '51 is incapable of.

    the above is correct for a LED on p1.0 lighting up when p1.1 is pulled low. Of course, that is only true if you have a pullup resistor on p1.1

    Erik

Children