Gast
#77436
Hallo alle miteinander, ich bin noch ein Anfänger mit dem Avr programmieren und hab da ein Problem, vielleicht kann mir jemand hier im Forum weiterhelfen? :-) Ich möchte gern am PORTD PIN 0 eine LED ein und ausschalten können, mit einem Schalter der am PIN 1 am selben PortD hängt. Ich habe mir mein Programm mal angehängt leider funkioniert es nicht. Hat jemand eine IDEE? Ich denke das es an der Delay funktion liegen könnte, siehe weiter unten. Ich benutze WIN-AVR und ponyprog2000 für den ATmega103 bei 6MHz. Gruss die amme #include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #include <avr/iom103.h> #include <avr/tt_delay.h> uint8_t k = 1; SIGNAL(SIG_INTERRUPT1) { if(k == 1) { outp(0x00,DDRD); //Port 0 und 1 als eingang k = 0; } else { outp(0x01,DDRD); k = 1; } delay_us(30000); /*30 us zum entprellen des Tasters*/ } int main(void) { outp(0x01,DDRD); //PIN0 an PortD als ausgang rest als eingang outp(0x02, EIMSK); //enable Interrupt 1 statt (1<<INT1) nun 0x02 outp((1<<ISC41), MCUCR);// External Interrupt Control Register sei(); while(1) {} return 0; } /*tt_delay.h*/ typedef unsigned int U16; #define CLOCKS_PER_US ((U16)(6)) //Zahl in MHz #define CLOCKS_PER_LOOP 4 static inline void my_delay_loop(unsigned int __count) { if (__count) { asm volatile ( "1: sbiw %0,1" "\n\t" "brne 1b" : "=w" (__count) : "0" (__count) ); } } #define delay_us(t) do{U16 c = (t)*CLOCKS_PER_US/CLOCKS_PER_LOOP; \ my_delay_loop(c); }while(0);