Hallo Leute,
ich habe miraus der Wiki dieses Beispiel herausgesucht und versucht in meinen Aufbau zu integrieren: Taster-Abfrage in C
Nur leider tut das ganze nicht so wie es soll.
Mein Beispiel sieht folgendermaßen aus:
Bei einem Tastendruck passiert leider nichts.Code://---------------------------------------- // Titel : Arcade Tastenprogrammierung //---------------------------------------- #include <avr/io.h> #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <avr/eeprom.h> #include "taster.h" typedef unsigned char BYTE; typedef unsigned int WORD; BYTE bPortB; BYTE nKeyPress; uint8_t eeFooByte; volatile uint8_t gKeyCounter; volatile signed char taster = NO_TASTER; taste_t tasten[NUM_TASTER]; const unsigned char Tabelle[] PROGMEM = {249, 164, 176, 153, 146, 130, 248, 128, 144}; SIGNAL (SIG_OVERFLOW0) { static unsigned char count_ovl0; unsigned char ovl0 = count_ovl0+1; if (ovl0 >= 39) { get_taster (1, PINB & (1<<PB4)); ovl0 = 0; } count_ovl0 = ovl0; } void ioinit() { PORTB |= 1 << PB4; DDRD = 0xFF; TCCR0 = 1 << CS00; TIMSK |= (1 << TOIE0); } int main (void) { ioinit(); bPortB = 1; nKeyPress = 0; // nKeyPress = eeprom_read_byte(&eeFooByte); gKeyCounter = 0; tasten[0].mode = TM_SHORT; tasten[1].mode = TM_LONG; tasten[2].mode = TM_REPEAT; while(1) { signed char tast = taster; PORTD = pgm_read_byte(&Tabelle[nKeyPress]); switch (tast) { default: case NO_TASTER: break; case 1: if (nKeyPress < 8) { nKeyPress++; } else { nKeyPress = 0; } break; case 1+TASTER_LONG: eeprom_write_byte(&eeFooByte, nKeyPress); break; } if (tast != NO_TASTER) taster = NO_TASTER; } return 0; } void get_taster (const unsigned char num, unsigned char tast) { const taste_t * const ptast = & tasten[num]; const unsigned char taster_old = ptast->old; unsigned char pressed, press, release, mode, delay; #if TASTER_LEVEL tast = !!tast; #else tast = !tast; #endif /* Taster bleibt gedrueckt */ pressed = taster_old & tast; /* Taster neu gedrueckt */ press = ~taster_old & tast; /* Taster losgelassen */ release = taster_old & ~tast; *((unsigned char *) & ptast->old) = tast; tast = NO_TASTER; mode = ptast->mode; delay = ptast->delay; if (press) { if (mode != TM_LONG) tast = num; delay = 0; } else if (pressed) { if (delay < 0xfe) delay++; } else if (release) { if (mode == TM_LONG && delay != 0xff) tast = num; } if (mode == TM_LONG) { if (delay == TASTER_DELAY_LONG) { tast = TASTER_LONG + num; delay = 0xff; } } else if (mode == TM_REPEAT) { if (delay == TASTER_REPEAT_DELAY) { tast = num; delay = TASTER_REPEAT_DELAY - TASTER_REPEAT; } } if (taster == NO_TASTER) taster = tast; *((unsigned char *) & ptast->delay) = delay; }
Hat jemand eine Idee wo da der Hund begraben sein könnte?







Zitieren


Lesezeichen