jokester4u
Junior Member level 2
How do i set a time for a line follwing r0b0t when it start from one place and when it get reversed it should stop on the same location where its started?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include<reg2051.h> unsigned int m; void delay() {for(m=0;m<=20;m++) { TMOD=0X01; TL0=0xFD; TH0=0X4B; TR0=1; while(TF0==0); TR0=0; TF0=0;}} /// one sec delay sbit L=P3^2; sbit M=P3^3; sbit R=P3^4; void main () { P1=0x00; P3=0xFF; if (L==1&&M==0&&R==1) {P1=0x05;} // forward else if (L==1&&M==1&&R==1) {P1=0x0A;} } // reverse
#include<p89v51rd2.h>
unsigned int a=0,steps=0,b=0;
void Timer(void) interrupt 1 // Interrupt No.1 for T0
{
TH0=0x4b;
TL0=0xfc;
if(a==20)
{
steps++; // after 1 sec
a=0;
// if stop is signaled for the robot,stop the timer
}
a++;
}
void Timer1(void) interrupt 3 // Interrupt No.3 for T2
{
TH0=0x4b;
TL0=0xfc;
if(b==20)
{
steps--;
b=0;
if(steps==0)
{
TR1=0; // stop timer
// stop the robot
}
}
b++;
}
void main()
{
unsigned int fwd=0,rev=0;
TMOD = 0x11; // Mode1 of Timer0 & mode 1 of timer 1
IEN0 = 0x8a; // Enable interrupt
while(1)
{
if(fwd==1)
{
TH0=0x4b; // Initial values loaded to Timer
TL0=0xfc;
TR0=1;
}
if(rev==1)
{
TH1=0x4b; // Initial values loaded to Timer
TL1=0xfc;
TR1=1;
}
}