written 5.6 years ago by
teamques10
★ 66k
|
•
modified 5.6 years ago
|
The program
# include< reg51.h>
sbit relay = P2^2;
sbit sensor = P3^4;
void main (void)
{
sensor=1; $\hspace{1.5cm}$ //P3.4 as input line
relay = 0; $\hspace{1.5cm}$ // Intially OFF
while (1)
{
while ( sensor == 0); $\hspace{1.5cm}$ // check sensor if no dark wait//
relay = 1; $\hspace{1.5cm}$ // dark ON bulb//
while ( sensor == 1); $\hspace{1.5cm}$ // wait till dark//
}
}
$\hspace{4.5cm}$**OR**
# include< reg51.h>
sbit relay = P2^2;
sbit sensor = P3^4;
void main (void)
{
sensor=1;$\hspace{1.5cm}$ //P3.4 as input line
relay = 0; $\hspace{1.5cm}$// Intially OFF
while (1)
{
if ( sensor == 1) $\hspace{1.5cm}$ // check sensor if dark //
relay = 1; $\hspace{1.5cm}$ // ON bulb//
else
relay=0;
}
}