Society of Robots - Robot Forum

Software => Software => Topic started by: lobo on October 01, 2008, 12:00:19 AM

Title: c program for sonar for atmega8
Post 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.
Title: Re: c program for sonar for atmega8
Post by: Ro-Bot-X on October 01, 2008, 05:42:50 AM
If you search for Ping, you'll find it.
Title: Re: c program for sonar for atmega8
Post by: pomprocker on October 01, 2008, 12:42:18 PM
Click the link in my signature
Title: Re: c program for sonar for atmega8
Post by: fendi on October 19, 2008, 10:15:02 AM
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;
}