Hab das ganze jetzt nochmal umgestrickt und denke das ich am richtigen Weg bin:
Mit den initialisieren der Interrupts bin ich nur etwas überfragt. Wie macht man das richtig?Code://---------------------------------------- // Titel : Arcade Tastenprogrammierung //---------------------------------------- #include <avr/io.h> #include <avr/interrupt.h> #include <stdint.h> #include <avr/eeprom.h> #include <avr/pgmspace.h> typedef unsigned char BYTE; typedef unsigned int WORD; BYTE bPortB; BYTE nKeyPress; const unsigned char Tabelle[] PROGMEM = {249, 164, 176, 153, 146, 130, 248, 128, 144}; #define CNTDEBOUNCE 10 #define CNTREPEAT 200 #define KEY_PIN PINB #define KEY_PINNO PB6 uint8_t eeFooByte; volatile uint8_t gKeyCounter; ISR(TIMER1_COMPA_vect) { uint8_t tmp_kc; tmp_kc = gKeyCounter; if (!(KEY_PIN & (1<<KEY_PINNO))) { if (tmp_kc < CNTREPEAT) { tmp_kc++; } } else { tmp_kc = 0; } gKeyCounter = tmp_kc; } void init(void) { PORTB |= _BV(6); // Pull-Up Port B6 aktivieren DDRB = 0xFF; // Port B als Eingang DDRD = 0xFF; // Port D als Ausgang TIMSK |= (1<<TOIE1); //Timer1 Interrupt aktiviert TCCR1B = 1; //Prescaler 1 TCNT1 = 65535-3600; //Preloader 3600 } int main (void) { init(); sei(); bPortB = 1; nKeyPress = eeprom_read_byte(&eeFooByte); while(1) { if ( gKeyCounter > CNTDEBOUNCE ) { if (gKeyCounter == CNTREPEAT) // Code fuer "Taste lange gedrueckt" { eeprom_write_byte(&eeFooByte, nKeyPress); } else // Code fuer "Taste kurz gedrueckt" { PORTD = pgm_read_byte(&Tabelle[nKeyPress]); if (nKeyPress < 8) { nKeyPress++; } else { nKeyPress = 0; } } } } return 0; }
Wie gesagt ich verwende einen ATMEGA8 mit 8MHz Takt.







Zitieren
Lesezeichen