Vielen Dank für deine Antwort!
Ich habe deine Vorschläge befolgt.
leider bisher ohne erfolg![]()
Ich nicht genau was du mit "INT0 resp. INT1-Flags nach Anfassen von MCUCSR clearen?" meinst?
und was kann ich anstelle der float's machen?
Vielen Dank!
Chris
der Code im moment:
Code:#include <inttypes.h> #include <avr/interrupt.h> #define F_CPU 8000000 /* 8Mhz */ #include <util/delay.h> /* definiert _delay_ms() ab avr-libc Version 1.2.0 */ #include "twimaster.c" #include "LCD.h" volatile long t2_y,t2_x; volatile long t1_y,t1_x; volatile int x1,x0; // Temp Variablen für adxl und main int count_y, count_x; char ziel[5]; ISR(SIG_INTERRUPT1){ cli(); if(x1==1){ x1=0; if(x0==1) MCUCR = (1<<ISC11 | 1<<ISC10 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC11 | 1<<ISC10 | 1<<ISC01 | 0<<ISC00); t1_y = count_y; } else{ x1=1; if(x0==1) MCUCR = (1<<ISC11 | 0<<ISC10 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC11 | 0<<ISC10 | 1<<ISC01 | 0<<ISC00); t2_y = count_y; count_y = 0; } sei(); } ISR(SIG_INTERRUPT0){ cli(); if(x0==1){ x0=0; if(x1==1) MCUCR = (1<<ISC01 | 1<<ISC00 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC01 | 1<<ISC00 | 1<<ISC01 | 0<<ISC00); t1_x = count_x; } else{ x0=1; if(x1==1) MCUCR = (1<<ISC01 | 0<<ISC00 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC01 | 0<<ISC00 | 1<<ISC01 | 0<<ISC00); t2_x=count_x; count_x = 0; } sei(); } ISR (SIG_OUTPUT_COMPARE1A){ count_y++; count_x++; } void Timer_Inits(void){ TCCR1A = 0; TCCR1B = (1 << WGM12) | (1 << CS10); OCR1A = (uint16_t) ((uint32_t) F_CPU / 50000); //100000 TIMSK |= (1 << OCIE1A); // Interrupt wenn Timer Vergleichswert erreicht GIMSK = (1<<INT0 | 1<<INT1); //Int0,1 aktiv // GIMSK = (1<<INT1); //Int0,1 aktiv } int main (void){ DDRC = 0x00; //alles als Eingan def. PORTC =0x00; //PullUp's aus DDRD =0x00; //alles Eingang PORTD =0x00; //PullUp's aus Timer_Inits(); sei(); i2c_init(); _delay_ms(10000); lcd_init(); _delay_ms(10000); for(;;){ _delay_ms(90000000);_delay_ms(90000000);_delay_ms(90000000); clear(); int result; (int)result = (((((float)t1_y/(float)t2_y)*1000)-481)*1000)/125; sprintf(ziel,"%d",result); stringout ("a_y="); stringout (ziel); result = (((((float)t1_x/(float)t2_x)*1000)-481)*1000)/125; sprintf(ziel,"%d",result); stringout (" a_x="); stringout (ziel); // if(result>4) PORTC|=(1<<PC3); //LED2 anschalte // else PORTC&=~(1<<PC3); // if(result>6000) PORTC|=(1<<PC2); //LED1 anschalte // else PORTC&=~(1<<PC2); // if(result>7) PORTC|=(1<<PC1); //LED0 anschalte // else PORTC&=~(1<<PC1); // if(result>8) PORTC|=(1<<PC0); //LED0 anschalte // else PORTC&=~(1<<PC0); } }






Zitieren

Lesezeichen