Und diesen Ausgang schaltet man nach low (GND) damit man die internen Pullups nutzen kann.Oder Einfach alle auf Eingang schalten, mit PullUp, und nur eine Reihe auf Ausgang?
Ich hab den Code schnell mal aus dem Kopf zusammengezimmert.Code:// Port C wäre der Tastaturport. // Portc.6 = Spalte 1 // Portc.5 = Spalte 2 // Portc.4 = Spalte 3 // Initialisierung ... PORTC=0b01111111; DDRC=0b00000000; ... // Tastaturabfrage: unsigned char read_tast(void) { taste1=15; // Tastenparameter vorbelegen -> keine Taste gedrückt taste2=15; PORTC.6=0; // Spalte 1 auf low DDRC.6=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste1=1; break; case 0b00001101: taste1=2; break; case 0b00001011: taste1=3; break; case 0b00000111: taste1=4; break; default: }; PORTC.6=1; // Spalte wieder auf high DDRC.6=0; PORTC.5=0; // Spalte auf low DDRC.5=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste1=5; break; case 0b00001101: taste1=6; break; case 0b00001011: taste1=7; break; case 0b00000111: taste1=8; break; default: }; PORTC.5=1; // Spalte wieder auf high DDRC.5=0; PORTC.4=0; // Spalte auf low DDRC.4=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste1=9; break; case 0b00001101: taste1=10; break; case 0b00001011: taste1=11; break; case 0b00000111: taste1=12; break; default: }; PORTC.4=1; // Spalte wieder auf high DDRC.4=0; delay_ms(10); // 2te Tastaturabfrage: PORTC.6=0; // Spalte 1 auf low DDRC.6=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste2=1; break; case 0b00001101: taste2=2; break; case 0b00001011: taste2=3; break; case 0b00000111: taste2=1; break; default: }; PORTC.6=1; // Spalte wieder auf high DDRC.6=0; PORTC.5=0; // Spalte auf low DDRC.5=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste2=5; break; case 0b00001101: taste2=6; break; case 0b00001011: taste2=7; break; case 0b00000111: taste2=8; break; default: }; PORTC.5=1; // Spalte wieder auf high DDRC.5=0; PORTC.4=0; // Spalte auf low DDRC.4=1; uc_tastabfr1=PINC&0b00001111; // Zeilen 1...4 ausfiltern switch (uc_tastabfr1) { case 0b00001110: taste2=9; break; case 0b00001101: taste2=10; break; case 0b00001011: taste2=11; break; case 0b00000111: taste2=12; break; default: }; PORTC.4=1; // Spalte wieder auf high DDRC.4=0; if(taste1==taste2) { return (taste1); } else { return(255); };
Es kann also sein das noch ein paar Fehler drin sind.
Ich meine aber das Prinzip ist erkennbar und somit für Dich umzusetzen.







Zitieren

Lesezeichen