Soho! ^^
Der Code sieht jetzt wiefolgt aus:
jetzt läfuts fast so wie ich will. Nur das wohl manchmal auch ohne Hinderniss der wert von "posmarker" über 13 steigt.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) { count72kHz = 0; TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20); // Toggling of IO-Pin on // generate the Chirp while(count72kHz < length) { OCR2 = 0x64 + length / 2 - count72kHz; } TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off OCR2 = 0x64; // set frequency to 40kHz } int main(void) { int pos, i; int posmarker; unsigned char aci,acsr; Init(); LocalInit(); while(TRUE){ posmarker = 0; Ping(20); for(pos = 0; pos < 100; pos++) { Sleep(10); aci = ( 1 << ACI ) ; acsr = ACSR & aci ; if ( acsr != 0 ) { if(posmarker == 0) { posmarker = pos; } } ACSR |= (1 << ACI); } if(posmarker < 13) { StatusLED(GREEN); MotorDir(FWD, RWD); MotorSpeed(0,170); } else { StatusLED(RED); MotorDir(FWD, FWD); MotorSpeed(200,200); for(i = 0; i<100; i++) { Sleep(200); } } } return 0; }







Zitieren

Lesezeichen