Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem while trying to give toggle inputs to 8051

Status
Not open for further replies.

jadedcynic

New Member
i am working on a device which will turn on or off the lights in a room depending upon whether the room is occupied or not. i am using the TSAL6200 as my ir transmitter and an ir detector(the one that looks like an led). two of these tx rx pairs are placed at the entrance to the room and depending on whether the external one gets blocked first or the internal one the count value increments or decrements. now my ir receiver seems to be working fine, i.e. it gives me a low voltage(about 0.2v ) in the absence of ir light and a high of about 2.67 in the presence of the ir light.

PROBLEM :
i am trying to give the output of my ir receiver to my uc. i am using the port 1 and the pins 1.0 and 1.1. the problem is that for me to set the uc port as an input port all of its pins need to be set to 0xFF(in c language), i.e. they all have a voltage of 5v, so when i try to force feed the output of my ir receiver to the uc all that happens is that the current flows from the higher potential to the lower potential and lights up the test leds of my circuit. the uc is not accepting my input.
i need the uc to be able to read the high and the low voltages which i am feeding it.
do i need to use the interrupt pins of port 3 for the uc to be able to accept my toggle inputs?

also in my program i am simply using two nested if conditions, do i need to use the counter section of the uc?

this is my initial program:
<reg51.h>


bit ir1=p1^0;
bit ir2=p1^1;
bit relay = p2^3;
int count=0;

//declarations

//ir1=0;//make p1.0 low
//ir2=0;//make p1.1 low

void delay(void)
{
int i;
for(i=0;i<30000;i++)
for(i=0;i<30000;i++)
}

void main(void)
{
while(1);
{

P1=0XFF;\\set port 1 as input
P2=0;\\set port two as output
if(ir1==0)
{
delay();
delay();
delay();
delay();
if(1r2==0)
count=count+1;
}

else if(ir2==0)
{
delay();
delay();
delay();
delay();

if(ir1==0)
count=count-1;
}

if(count==0)
{
relay=0;
}
if(count!=0)
{
relay=1;
}

}
}

help me please!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top