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);
Hallo, ich kann leider kein C, aber mir ist da was aufgefallen. 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*/ Da steht also 2mal outp und DDRD. Das obere macht Pin0 vom PortD zum Ausgang. Das untere macht das selbe mit Pin1 vom PortD. Das sind 2mal Datenrichtungsregister Befehle. Was ich vermisse ist die Anweisung eines Input vom PortD Pin1. Wie gesagt ich kann kein C, das ist mir aber aufgefallen. Gruß, Arno
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.