Society of Robots - Robot Forum
Software => Software => Topic started by: lobo on October 01, 2008, 12:00:19 AM
-
I was wondering if someone already posted a program in c for atmega8 to use for the parallax sonar.
I have two sonars and would like to write or paste a c program to uilize both for object avoidance.
thanks guys in advance.
-
If you search for Ping, you'll find it.
-
Click the link in my signature
-
this is my example program using parallax in atmega16.
void parallax(void)
{
start:
t=1;
DDRB.0=1;//set PORTB.0 as output n pull up
PORTB.0=1;
delay_us(5);
PORTB.0=0; //set PORT B.0 as input
DDRB.0=0;
PORTB.0=1 ;
for(i=0;i<1050;i++) //if there is no echo recive till i=1050 go to start
{
if(PINB.0==1)//recive echo
goto coun;
}
goto start;
coun:
if(PINB.0==0)
goto hitung;
t=t+1 ;
delay_us(1);
goto coun;
hitung:
s=340*1000000*t/2 //count the distance in m
delay_ms(10);
return;
}