Sei sulla pagina 1di 2

#include<avr/io.

h>
#include<util/delay.h>
void wait(float sec, int freq) //wait function to create time delay
{
for(int i=0;i<(int)(46*sec);i++)
_delay_loop_2(0);
}
int main(void)
{
int DTMF=0; //DTMF variable for mean while checking
DDRB=0xFF; //PORTB as output Port connected to motors
DDRC=0b0000000; //PORTC Input port connected to DTMF decoder IC
while(1) // infinite loop
{
DTMF=PINC;
DTMF=DTMF&0b0001111; //Mask high order 3 bits exposed low order 4 bits
if(DTMF==2) //if Key 2 of cell phone pressed
{
PORTB=0b00010010; // move straight
}
if(DTMF==4) // if Key 4 of cell phone pressed
{
PORTB=0b00000010; // turn left
}
if(DTMF==6) // if Key 6 of cell phone pressed
{
PORTB=0b000010000; // turn right
}
if(DTMF==8) // if Key 8 of cell phone pressed
{
PORTB=0b00001100; // move back
}
if(DTMF==11) // if Key * of cell phone pressed
{
PORTB=0b00000000; //stop
}
if(DTMF==12) // if key # of cell phone pressed
{
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 PC0
rs=(PINC&0b0001000); // acquire only right sensor status connected at
PC3
if((ls==0b0000000)&(rs==0b0000000)) //check sensor status for bo
th sensor OFF
{
PORTB=0b00000000; //stop
ls=0; //set sensor status off
rs=0; //set sensor status off
}
if((ls==0b0000001)&(rs==0b0000000)) //check sensor status for le
ft sensor=ON and
// right sensor=OFF
{
PORTB=0b00010000; //turn right
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=0b00000010; //turn left
ls=0; //set sensor status off
rs=0; //set sensor status off
}
if((ls==0b0000001)&(rs==0b0001000)) //check sensor status for both senso
r ON
{
PORTB=0b00010010; //move forward
ls=0; //set sensor status off
rs=0; //set sensor status off
}
}
}

}//while closed
}//main closed

Potrebbero piacerti anche