pratti
Member level 3
- Joined
- Jun 15, 2013
- Messages
- 56
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 471
#include<reg51.h>
#include<stdio.h>
//port2 for load(stepper motor): ort3 for ldrs(sensors): ort 1 for solarpanel
#define motor p2;
#define high 1;
#define low 0;
sfr stepper_motor; //to determine the direction of motor (east,middle,west)
unsigned int i,j,count,count1;
sbit ldr1=P3^2; //initializing the bit of port 3
sbit ldr2=P3^3;
sbit ldr3=p3^4 //signals from sensor
sbit reset=p1^0//reset
void T0Delay(void); //for delay signal
clock(); // for clockwise rotation
clock1();
clock2();
clockfast();
clockfast1();
clockfast2();
anticlock();//for anticlockwise
rest();
//for rest at east position
main() //LDR : WHEN LIGHT FALLS ON IT,IT GIVES THE SIGNAL TO THE MICROCONTROLLER
{
// WHEN NO LIGHT OUTPUT IS =0;
// WHEN LIGHT OUTPUT IS =1;
p1=00; //initialsing all port to zero;
p0=00;
p3=0xFF; //initializing port 3 to input
p2=0x00;
//initializing port 2 to output
while(0<count<=60|0<count1<=15)) //while tracking the sun to determine the position of stepper motor or moving fast to search the light
{
stepper_motor=1
}
while(60<count<=120|15<count1<=45)
{
stepper_motor=2
]
while(120<count<=180|45<count1<=60)
{
stepper_motor=3
}
while(p3=1) //when port 3 gets any signal ie when it get ldr get light
{
if(ldr1=1&&ldr2=0&&ldr3=0) //when signal came from 1st ldr
{
if (stepper_motor==1) //when motor is in the east postion
{
clockwise(); //rotate clockwise in a full 180
}
else if(stepper_motor==2) //when motor is in the middle position and ldr1 gets light
{
clockwise2(); //rotate clockwie from middle so only half rotation is required
}
else
{
clockwise3(); //rotate clockwise from west for little time only
T0delay(); //wait in west for sometime
anticlockwise();//move back to east fo the next day
T0delay(); //wait their for some time
rest(); //rest
}
if(ldr1=0&&ldr2=1&&ldr3=0) //when light falls on 2nd ldr
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=0&&ldr2=0&&ldr3=1) //when light falls on 3rd ldr
{
if(stepper_motor==1);
{
clock();
}
else if(stepper_motor=2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
while(ldr1=0&&ldr2=0&&ldr3=1)
{
if(stepper_motor=1);
{
clock();
}
else if(stepper_motor=2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=1&&ldr2=1&&ldr3=0)//both ldr receives light
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
}
if(ldr=1&&ldr2=0&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=0&&ldr2=1&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
delay();
rest();
}
if(ldr1=1&&ldr2=1&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
}
} //WHILE1
}//MAIN
while(p3=0)//for no light search for the light by rotating left and right
{
if(ldr1=0&&ldr2=0&&ldr3=0)
{
rest();
T0delay()
for(i=1;i<4;i++) //for four times rotation continues
{
if(stepper_motor=1) //when stepper motor is in east position and no light falls
{
clockfast(); //rotate clockwise
}
elseif
{
stepper_motor=2
{
clockfast1(); //rotate half clockwise
}
else
{
stepper_motor=3
{
clockfast2(); //rotate little clockwise
}
T0delay1(); //wait for smtine in west position
anticlock(); //rotate anticlockwise
clockfast(); //rotate clockwise
T0delay1(); //wait fir smtime
rest();
reset=1; //rest position
}
clock() //function for clockwise rotation
{
for(counter=0;count<=200-count;counter++)
{
P2=0X11;
T0delay(56);
P2=0X22;
T0delay(56);
P2=0X44;
T0delay(56);
P2=0X88;
T0delay(56);
}
}
anticlock() //function for clockwise
{
for(counter=0;count<=200-count;counter++)
{
P2=0X88;
T0delay(75);
P2=0X44;
T0delay(75);
P2=0x22;
T0delay(75);
P2=0X11;
T0delay(75);
}
}
}
clock1(); //function for halg clockwise
{
for(count=1;count<=90-count;count++)
p2=0x11;
T0delay(56);
p2=0x22;
T0delay(56);
p2=0x44;
T0delay(56);
p2=0x88;
T0delay(56);
}
}
clock2(); //function for little clockwise
{
for(count=1;count<=45-count;count++)
{
p2=0x11;
T0delay(56);
p2=0x22;
T0delay(56);
p2=0x44;
T0delay(56);
p2=0x88;
T0delay(56);
}
}
rest() //at rest position
{
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
}
clockfast() //function for clockwise rotation
{
for(counter=0;counter<=100-count;counter++)
{
P2=0X11;
T0delay1(56);
P2=0X22;
T0delay1(56);
P2=0X44;
T0delay1(56);
P2=0X88;
T0delay1(56);
}
}
clockfast1(); //function for halg clockwise
{
for(count=1;count1<=45-count;count++)
{
p2=0x11;
T0delay1(56);
p2=0x22;
T0delay1(56);
p2=0x44;
T0delay1(56);
p2=0x88;
T0delay1(56);
}
}
clockfast2(); //function for little clockwise
{
for(count=1;count1<=15-count;count++)
{
p2=0x11;
T0delay1(56);
p2=0x22;
T0delay1(56);
p2=0x44;
T0delay1(56);
p2=0x88;
T0delay1(56);
}
}
//delay(unsigned int time) //delay function
//{
//unsigned int i,j;
//for(i=0;i<time;i++)
//for(j=0;j<1275;j++)
//}
void T0Delay() //delay by using timer
{
TMOD=0×01; // timer 0, mode 1
TL0=0×00; // load TL0
TH0=0×35; // load TH0
TR0=1; // turn on Timer0
while (TF0==0); // wait for TF0 to roll over
TR0=0; // turn off timer
TF0=0; // clear TF0
}
void T0Delay1() //delay by using timer
{
TMOD=0×01; // timer 0, mode 1
TL0=0×00; // load TL0
TH0=0×35; // load TH0
TR0=1; // turn on Timer0
while (TF0==0); // wait for TF0 to roll over
TR0=0; // turn off timer
TF0=0; // clear TF0
}
#include<stdio.h>
//port2 for load(stepper motor):
#define motor p2;
#define high 1;
#define low 0;
sfr stepper_motor; //to determine the direction of motor (east,middle,west)
unsigned int i,j,count,count1;
sbit ldr1=P3^2; //initializing the bit of port 3
sbit ldr2=P3^3;
sbit ldr3=p3^4 //signals from sensor
sbit reset=p1^0//reset
void T0Delay(void); //for delay signal
clock(); // for clockwise rotation
clock1();
clock2();
clockfast();
clockfast1();
clockfast2();
anticlock();//for anticlockwise
rest();
//for rest at east position
main() //LDR : WHEN LIGHT FALLS ON IT,IT GIVES THE SIGNAL TO THE MICROCONTROLLER
{
// WHEN NO LIGHT OUTPUT IS =0;
// WHEN LIGHT OUTPUT IS =1;
p1=00; //initialsing all port to zero;
p0=00;
p3=0xFF; //initializing port 3 to input
p2=0x00;
//initializing port 2 to output
while(0<count<=60|0<count1<=15)) //while tracking the sun to determine the position of stepper motor or moving fast to search the light
{
stepper_motor=1
}
while(60<count<=120|15<count1<=45)
{
stepper_motor=2
]
while(120<count<=180|45<count1<=60)
{
stepper_motor=3
}
while(p3=1) //when port 3 gets any signal ie when it get ldr get light
{
if(ldr1=1&&ldr2=0&&ldr3=0) //when signal came from 1st ldr
{
if (stepper_motor==1) //when motor is in the east postion
{
clockwise(); //rotate clockwise in a full 180
}
else if(stepper_motor==2) //when motor is in the middle position and ldr1 gets light
{
clockwise2(); //rotate clockwie from middle so only half rotation is required
}
else
{
clockwise3(); //rotate clockwise from west for little time only
T0delay(); //wait in west for sometime
anticlockwise();//move back to east fo the next day
T0delay(); //wait their for some time
rest(); //rest
}
if(ldr1=0&&ldr2=1&&ldr3=0) //when light falls on 2nd ldr
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=0&&ldr2=0&&ldr3=1) //when light falls on 3rd ldr
{
if(stepper_motor==1);
{
clock();
}
else if(stepper_motor=2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
while(ldr1=0&&ldr2=0&&ldr3=1)
{
if(stepper_motor=1);
{
clock();
}
else if(stepper_motor=2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=1&&ldr2=1&&ldr3=0)//both ldr receives light
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
}
if(ldr=1&&ldr2=0&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
if(ldr1=0&&ldr2=1&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
delay();
rest();
}
if(ldr1=1&&ldr2=1&&ldr3=1)
{
if(stepper_motor==1)
{
clock();
}
elseif(stepper_motor==2)
{
clock1();
}
else
{
clock2();
T0delay();
anticlockwise();
T0delay();
rest();
}
}
} //WHILE1
}//MAIN
while(p3=0)//for no light search for the light by rotating left and right
{
if(ldr1=0&&ldr2=0&&ldr3=0)
{
rest();
T0delay()
for(i=1;i<4;i++) //for four times rotation continues
{
if(stepper_motor=1) //when stepper motor is in east position and no light falls
{
clockfast(); //rotate clockwise
}
elseif
{
stepper_motor=2
{
clockfast1(); //rotate half clockwise
}
else
{
stepper_motor=3
{
clockfast2(); //rotate little clockwise
}
T0delay1(); //wait for smtine in west position
anticlock(); //rotate anticlockwise
clockfast(); //rotate clockwise
T0delay1(); //wait fir smtime
rest();
reset=1; //rest position
}
clock() //function for clockwise rotation
{
for(counter=0;count<=200-count;counter++)
{
P2=0X11;
T0delay(56);
P2=0X22;
T0delay(56);
P2=0X44;
T0delay(56);
P2=0X88;
T0delay(56);
}
}
anticlock() //function for clockwise
{
for(counter=0;count<=200-count;counter++)
{
P2=0X88;
T0delay(75);
P2=0X44;
T0delay(75);
P2=0x22;
T0delay(75);
P2=0X11;
T0delay(75);
}
}
}
clock1(); //function for halg clockwise
{
for(count=1;count<=90-count;count++)
p2=0x11;
T0delay(56);
p2=0x22;
T0delay(56);
p2=0x44;
T0delay(56);
p2=0x88;
T0delay(56);
}
}
clock2(); //function for little clockwise
{
for(count=1;count<=45-count;count++)
{
p2=0x11;
T0delay(56);
p2=0x22;
T0delay(56);
p2=0x44;
T0delay(56);
p2=0x88;
T0delay(56);
}
}
rest() //at rest position
{
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
p2=0x00;
T0delay(56);
}
clockfast() //function for clockwise rotation
{
for(counter=0;counter<=100-count;counter++)
{
P2=0X11;
T0delay1(56);
P2=0X22;
T0delay1(56);
P2=0X44;
T0delay1(56);
P2=0X88;
T0delay1(56);
}
}
clockfast1(); //function for halg clockwise
{
for(count=1;count1<=45-count;count++)
{
p2=0x11;
T0delay1(56);
p2=0x22;
T0delay1(56);
p2=0x44;
T0delay1(56);
p2=0x88;
T0delay1(56);
}
}
clockfast2(); //function for little clockwise
{
for(count=1;count1<=15-count;count++)
{
p2=0x11;
T0delay1(56);
p2=0x22;
T0delay1(56);
p2=0x44;
T0delay1(56);
p2=0x88;
T0delay1(56);
}
}
//delay(unsigned int time) //delay function
//{
//unsigned int i,j;
//for(i=0;i<time;i++)
//for(j=0;j<1275;j++)
//}
void T0Delay() //delay by using timer
{
TMOD=0×01; // timer 0, mode 1
TL0=0×00; // load TL0
TH0=0×35; // load TH0
TR0=1; // turn on Timer0
while (TF0==0); // wait for TF0 to roll over
TR0=0; // turn off timer
TF0=0; // clear TF0
}
void T0Delay1() //delay by using timer
{
TMOD=0×01; // timer 0, mode 1
TL0=0×00; // load TL0
TH0=0×35; // load TH0
TR0=1; // turn on Timer0
while (TF0==0); // wait for TF0 to roll over
TR0=0; // turn off timer
TF0=0; // clear TF0
}