Also ich habe jetzt folgendes gemacht:
1) die Funktionen

/**************** Ultraschall asuro.c **************************/
void InitUltrasonics(void);
void RestoreAsuro(void);
int Chirp(void);
/* ----------- END ------------ */

in asuro.h deklariert und in asuro.c implementiert

2) Diese Funktion ist nun in asuro.c

ISR(TIMER2_COMP_vect)
{
//TCNT2 += 0x25;
count36kHz++;
if(!count36kHz) timebase++;
}

3) Folgender Code als Test:

Code:
#include "asuro.h"
int abstand=0;

int main(void)
{
  Init();
  SerWrite("\r\n  --- ultrasonic test ---",29);
  Msleep(1000);
  
  do
  {
    abstand=Chirp();
    SerWrite("\r\n distanz in cm: ",20);
    Msleep(500);
    PrintInt(abstand);
  }
  while(1);
  return 0;
}
Ergebnis sieht interessant aus!!!

distanz in cm: 2
distanz in cm: 3
distanz in cm: 5
distanz in cm: 10
distanz in cm: 5
distanz in cm: 0
distanz in cm: 0
distanz in cm: 1
distanz in cm: 1
distanz in cm: 3
distanz in cm: 8
distanz in cm: 1
distanz in cm: 1
distanz in cm: 4
distanz in cm: 198
distanz in cm: 208
distanz in cm: 2
distanz in cm: 1
distanz in cm: 1
distanz in cm: 1
distanz in cm: 1
distanz in cm: 195
distanz in cm: 195

4) Als nächstes folgenden Code getestet:
Code:
#include "asuro.h"

void LocalInit(void)
{
	// Change Oscillator-frequency of Timer 2
	// to 40kHz, no toggling of IO-pin:
	TCCR2 = (1 << WGM21) | (1 << CS20);
	OCR2 = 0x64; // 40kHz @8MHz crystal
	ADCSRA = 0x00; // ADC off // Analog comparator:
	ACSR = 0x02; // Generate interrupt on falling edge
	ADMUX = 0x03; // Multiplexer for comparator to // ADC pin 3
	SFIOR |= (1 << ACME); // Enable muliplexing of comparator
	DDRD &= ~(1 << 6); // Port D Pin 6 is input!
}

void Ping(unsigned char length)
{
	count36kHz = 0;
	TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20);
	// Toggling of IO-Pin on // generate the Chirp
	while((count36kHz*2) < length) 
	{
		OCR2 = 0x64 + length / 2 - count36kHz*2;
	}
	TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off
	OCR2 = 0x64; // set frequency to 40kHz
}

int main(void)
{
	int pos, i;
	int posmarker;
	Init();
	LocalInit();
	while(TRUE) 
	{
		posmarker = 0;
		Ping(20);
		for(pos = 0; pos < 100; pos++) 
		{
			Sleep(10);
			if((ACSR & (1 << ACI)) != 0) 
			{
				if(posmarker == 0) { posmarker = pos; }
			}
			ACSR |= (1 << ACI);
		} 
		
		if(posmarker>10) 
		{ 
			StatusLED(GREEN);
			MotorDir(FWD, FWD);
			MotorSpeed(200, 200);
		}
		else 
		{
			StatusLED(RED);
			MotorDir(FWD, RWD);
			MotorSpeed(0, 200);
			for(i = 0; i<100; i++) 
			{ Sleep(200); }
		}
	}
	return 0;
}
Nichts funktioniert, nur grünes Licht.

Frage:
Hier könnte man doch abstand=Chirp(...) verwenden. Kann bitte mal jemand den Code aus dem Band 1 umschreiben? Ich stehe noch etwas auf dem Schlauch.