Gast
#953714
Hallo zusammen ich bin Anfänger in C-programmierung und möchte zwei Taster nutzen. Ich will dazu die folgende Routine nutzen: http://www.mikrocontroller.net/articles/Entprellung Nur ist das Beispiel ja nur für einen Taster beschrieben. Wie muß ich denn Quelltext ändern? Problem mit der Variable Zustand, muss je eine für jeden Taster geben #define TASTERPORT PINC #define button1 PINC2 #define button2 PINC3 -------------------------------------------- //Hauptprogramm int main (void){ char ret; DDRC = 0b11110011; while(1){ ret=taster(button1); if (ret){ PORTB ^= (1<<PB0); } /* ret=taster(button2); if (ret){ PORTB ^= (1<<PB1); } .... */ } // while end } // main end --------------------------------------------- char taster(unsigned char TASTERBIT) { static unsigned char zustand; char rw = 0; if(zustand == 0 && !(TASTERPORT & (1<<TASTERBIT))) //Taster wird gedrueckt (steigende Flanke) { zustand = 1; rw = 1; } else if (zustand == 1 && !(TASTERPORT & (1<<TASTERBIT))) //Taster wird gehalten { zustand = 2; rw = 0; } else if (zustand == 2 && (TASTERPORT & (1<<TASTERBIT))) //Taster wird losgelassen (fallende Flanke) { zustand = 3; rw = 0; } else if (zustand == 3 && (TASTERPORT & (1<<TASTERBIT))) //Taster losgelassen { zustand = 0; rw = 0; } return rw; }