Obstacle Avoider Atmega8 Mini

Published on January 2017 | Categories: Documents | Downloads: 20 | Comments: 0 | Views: 103
of 2
Download PDF   Embed   Report

Comments

Content

#include<avr/io.h> #include<util/delay.h> void main() { DDRC=0b0000000; //set PORTC as input port DDRB=0b00011110; //PB1, PB2, PB3, PB4 as output port int ls=0, rs=0; // define & initialize ls, rs integer as 0 to // acquire the left sensor statu s in ls and right sensor // status in rs while(1) // create infinite loop { ls=(PINC&0b0000001); //acquire only left sensor status connected at PC 0 rs=(PINC&0b0001000); // acquire only right sensor status connected at PC3 if((ls==0b0000001)&(rs==0b0001000)) //check sensor status for both senso r ON { PORTB=0b00001100; _delay_ms(700); PORTB=0b00010000; _delay_ms(800); ls=0; rs=0; } if((ls==0b0000001)&(rs==0b0000000)) //check sensor status for l eft sensor=ON and // right sensor=OFF { PORTB=0b00001100; //move back _delay_ms(700); //keep on moving back for 0.7 sec PORTB=0b00010000; //turn right _delay_ms(800); //keep on turning right for 0.8 sec ls=0; //set sensor status OFF rs=0; //set sensor status OFF } if((ls==0b0000000)&(rs==0b0001000)) //check sensor status for le ft sensor=OFF and // right sensor=ON { PORTB=0b00001100; //move back _delay_ms(700); //keep on moving back for 0.7 sec PORTB=0b00000010; //turn left _delay_ms(800); //keep on turning left for 0.8 sec ls=0; rs=0; r OFF { //set sensor status OFF //set sensor status OFF //move back //keep on moving back for 0.7 sec //keep on turning right for 0.8 sec //set sensor status OFF //set sensor status OFF

} if((ls==0b0000000)&(rs==0b0000000)) //check sensor status for both senso

PORTB=0b00010010; //move forward ls=0; //set sensor status OFF rs=0; //set sensor status OFF } } }

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close