Sie sind auf Seite 1von 4

C:\Documents and Settings\Ad...\Obstacle Avoider.

c /* This program demostrates how to make an Autonomous Robot that moves around the room avoiding obstacles (Obstacle Avoider). Left Motor = M1 Right Motor = M2 Left Obstacle Sensor = P2_6 Right Obstacle Sensor = P2_7

*/

#include<p89v51rd2.h> void delay(int time) { int i,j; for(i=0;i<100;i++) { (j=0;j<time;j++); for // Function to Move the Robot F //M1 //M1 //M2 //M2 Forward bit high Backward bit low Backward bit low Forward bit high

} }

void forward() orward { P1_0=1; P1_1=0; P1_2=0; P1_3=1; delay(5); Page: 1

C:\Documents and Settings\Ad...\Obstacle Avoider.c P1_0=0; P1_1=0; P1_2=0; P1_3=0; } delay(20); //M1 //M1 //M1 //M1 Forward bit low Backward bit low Forward bit low Backward bit low

void left() owards Left { P1_0=0; P1_1=1; P1_2=0; P1_3=1; delay(25); P1_0=0; P1_1=0; P1_2=0; P1_3=0; } delay(5);

// Function to turn the Robot t //M1 //M1 //M2 //M2 Forward bit low Backward bit high Backward bit low Forward bit high

//M1 //M1 //M1 //M1

Forward bit low Backward bit low Forward bit low Backward bit low

void right() owards Right { P1_0=1; P1_1=0; Page: 2

// Function to turn the Robot t //M1 Forward bit high //M1 Backward bit low

C:\Documents and Settings\Ad...\Obstacle Avoider.c P1_2=1; P1_3=0; delay(25); P1_0=0; P1_1=0; P1_2=0; P1_3=0; } delay(5); //M1 //M1 //M1 //M1 Forward bit low Backward bit low Forward bit low Backward bit low //M2 Backward bit high //M2 Forward bit low

void main() { P1=0xf0; // configure Port1 as Output // if the buzzer switches ON permanently, use P1= 0xf0; P2=0xff; // configure Port2 as Input while(1) { if((P2_6==0)&&(P2_7==0)) s are facing obstacle { left (); }

// if both sensor

else if((P2_6==0)&&(P2_7==1)) // if left sensor is facing obstacle { right (); Page: 3

C:\Documents and Settings\Ad...\Obstacle Avoider.c } else if((P2_6==1)&&(P2_7==0)) // if right senso r is facing obstacle { left (); } else if((P2_6==1)&&(P2_7==1)) // if No sensor i s facing obstacle { forward (); } } }

Page: 4

Das könnte Ihnen auch gefallen