8051 Input

Status
Not open for further replies.
i think the program should be some thing like this....
#include<stdio.h>
#include<reg51.h>
void delay(int);
sbit inp_pin=P1^0;
void main()
{
P0=P1=P2=P3=0x00;
for(;
{
if(inp_pin==0)
{
P2=0x01; // assuming that u have connected the LED to pin no.21 of 8051;
delay(500);
}
if(inp_pin==1)
{
P2=0x00;
delay(500);
}
}
}
 
anilmudulakar said:
if(inp_pin==0)
{
P2=0x01; // assuming that u have connected the LED to pin no.21 of 8051;
delay(500);
}
if(inp_pin==1)
{
P2=0x00;
delay(500);
}
Please allow me to repeat myself:
mcs51mc said:
Why testing for 1 AND 0 on an input pin??
If it's not a 1 it has to be 0 or what else do you expect?? 0.5
Ever heard of the ELSE statement guys??
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…