Program for Obstacle Avoider

PROGRAM:

#include<avr/io.h>

int main(void)
{
  DDRA=0X00;                    // Initialization of PORTA as input
  PORTA=0XFF;
 
  DDRD=0XF0;                    // Initailization of PORTD as output
  PORTD=0X00;
 
  while(1)
  {
    if((PINA&0X01)==0X00)        // Right Sensor(at PA0) is detecting Obstacle
     {
     PORTD=0X10;                // Turn Left
     }
    else if((PINA&0X02)==0X00)    // Left Sensor(at PA1) is detecting Obstacle
     {
     PORTD=0x40;                // Turn Right
     }
    else
     {
     PORTD=0X50;                // Move Forward
     }
  }
 }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s