Eshal
Advanced Member level 1
- Joined
- Aug 29, 2012
- Messages
- 470
- Helped
- 16
- Reputation
- 32
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Nowhere :)
- Activity points
- 5,149
I believe you could have asked a clearer question. The "5V" point is at least misleading, 8051 logic threshold is somewhere between 1 and 2 V rather than 5V.This is not the answer to my question. First read my post then reply.
Code C - [expand] 1 2 3 4 5 6 7 8 9 if (P2_0) { P0 = 0xff; P1 = 0xff; P2 = 0xff; } else { // perform regular GPIO control }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <reg51.h> int main(){ P2 |= 0x01; // Set P2.0 as input while(1){ if((P2 & 0x01) == 0x01) // Input < Preset { // Code to be performed when value below preset } else // Input > Preset { // Code to be performed when value above preset } }
Now, the IR sensor connection at P2.1 work by pressing button i.e. it should turn on LED at P1.0 if and only if the output of the LDR comparator is high i.e. P2.0 is high otherwise IR sensor should not be able to turn on the LED at P1.0.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <reg51.h> int main(){ P2 |= 0x01; // Set P2.0 and P2.1 as input P1 &= 0x00; // Clear P1 while(1){ if((P2_1 == 0)&&(P2_0 == 1)) // Button Pressed, LDR dark { P1 |= 0x01; // LED on } else { P1 &= 0xFE; // LED off } }
Sorry but I don't see any code. It is totally blank. I am online using mobile phone. On other threads I can see codes. But here I can't see any code. :-/
Debounce the switch.
First of all, I am not a boy. I am a girl. So it should be like "Just polling for comparator outputs at the port. The button depicts the state of an IR LED as per her diagram." OK?Just polling for comparator outputs at the port. The button depicts the state of an IR LED as per his diagram.
@Pradhan.rachit
And also I don't know what is |= and &=.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?