Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Enabling or Disabling the pin in AT89C51 in C

Status
Not open for further replies.
Ohh I see.

And I have already tried with if((P2^1 == 0)&&(P2^0 == 0))
But yet result was same as I described above.

When LDR is dark and button is pressed then the LED at P1.0 should glow. It means its cathode which is connected at pin P1.0 should at low when LDR is dark and button is pressed.
 

Code:
[syntax=c]
#include <reg51.h>
int main(){
P2 |= 0x03;   // Set P2.0 and P2.1 as input
P1 &= 0x00;  // Clear P1
 
while(1){
if((P2_1 == 0)&&(P2_0 == 0)) // Button Pressed, LDR dark
{
   P1 &= 0xFE; // LED on
}
else
{
  P1 |= 0x01; // LED off
}
}
[/syntax]
 

@pradhan.rachit
heheheheheh....
I have also tried it already :)
You know, in this case LED at P1.0 is always on. No matter what other conditions are. It will not go off in any condition.
 

When do you want the LED to turn ON and when do you want it to be OFF ? Tell the conditions for LED ON and OFF.
 
  • Like
Reactions: Eshal

    Eshal

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top