Hallo Ihr lieben Leut... danke für eure Ratschläge aber ich hab den Fehler immer noch nicht gefunden, darum hab ich mal den vollständigen Code gepostet, vielleicht seht ihr ja den Fehler
Code:#include <../avr/include/io.h> #include <../avr/include/stdio.h> #include <../avr/include/stdlib.h> #include <../avr/include/interrupt.h> #include <../avr/include/avr/signal.h> //***************************************************************** #define UART_BAUD_RATE 9600 #define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16l)-1) //***************************************************************** void init(void); void timer1_init(void); int uart_putchar(char c); void ioinit(void); void delay_ms(unsigned int ms); volatile int left_trigger=0, right_trigger=0; /****************************************************** * * main program */ int main(void) { //int adc_value; left_trigger = 0; right_trigger = 0; init(); // init ports && ext Interrupts ioinit(); // init COM sei(); // Interrupts aktivieren fdevopen(uart_putchar, NULL, 0); timer1_init(); // init Timer1 printf("\n ...start Firmware 2.0.0.4 on POWER-T...\n"); while(1) // start an endless loop { delay_ms(500); printf("Left= %i, Right= %i \n",left_trigger,right_trigger); } return 0; } /****************************************************** * * Methode : to init the µC */ void init(void) { //configure INT0 & INT1 - the external interrupt GICR |= (1<<INT0) | (1<<INT1); MCUCR |= (1<<ISC00) | (1<<ISC01) | (1<<ISC10) | (1<<ISC11); DDRD &= ~((1 << DDD2) | (1 << DDD3)); // PD2, PD3 als Eingang (ext. Interrupt 0, 1) // DDRA = B00000111; // PortA Pin 0,1,2 as Output, all others as input /* define port a as imput ( A/D-converter inputs ) */ DDRA = 0x00; PORTA = 0x00; /* define port b as output*/ DDRB = 0xff; PORTB = 0x00; /* define port c as output*/ DDRC = 0xff; PORTC = 0x00; /* define port d as output*/ DDRD = 0xff; PORTD = 0x00; } /****************************************************** * */ SIGNAL (SIG_INTERRUPT0) { left_trigger ++; } SIGNAL (SIG_INTERRUPT1) { right_trigger ++; } /****************************************************** * * timer1_init */ void timer1_init(void) { // activate the regulaer 8 bit pwm (not inverted) // the WGM10 bit is declared as PWM10 in the datasheet TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<WGM10); //set the frequenz up to 14 khz (prescaler = 1) TCCR1B = (1<<CS10); // deactivate interrupts for timer1 // ATTENTION : the interrupts for all other timer are in the same register TIMSK &= ~0x3c; OCR1A = 0; OCR1B = 0; } /****************************************************** * * uart_putchar */ int uart_putchar(char c) { if (c == '\n') uart_putchar('\r'); while (!(UCSRA & (1<<UDRE))); UDR = c; return 0; } /****************************************************** * * ioinit */ void ioinit(void) { UCSRB = 0x08; //UART Transmitter aktivieren UBRRL = UART_BAUD_SELECT; //Baud Rate einstellen } /****************************************************** * * delay_ms */ void delay_ms(unsigned int ms) { unsigned int my_counter; while (ms) { my_counter = F_CPU / 5000; while (my_counter) { asm volatile ("nop"); my_counter--; } ms--; } }







Zitieren

Lesezeichen