Gast
#2483748
Hallo alle zusammen,
ich hab für ein Standard 3x4 Matrix Tastenfeld eine Routine geschrieben:
// start matrix routine
for (int i=1; i<4; i++)
{
if (i==1)
{
// set port 0 to check for 1, 4, 7, * at ports 4, 5, 6, 7
PORTD= 0b00000001;
if ( PIND & (1<<PIND4) )
b1 = true;
else
b1 = false;
if ( PIND & (1<<PIND5) )
b4 = true;
else
b4 = false;
if ( PIND & (1<<PIND6) )
b7 = true;
else
b7 = false;
if ( PIND & (1<<PIND7) )
bStar = true;
else
bStar = false;
PORTD= 0b00000000;
}
if (i==2)
{
// set port 1 to check for 2, 5, 8, 0 at ports 4, 5, 6, 7
PORTD= 0b00000010;
if ( PIND & (1<<PIND4) )
b2 = true;
else
b2 = false;
if ( PIND & (1<<PIND5) )
b5 = true;
else
b5 = false;
if ( PIND & (1<<PIND6) )
b8 = true;
else
b8 = false;
if ( PIND & (1<<PIND7) )
b0 = true;
else
b0 = false;
PORTD= 0b00000000;
}
if (i==3)
{
// set port 2 to check for 3, 6, 9, # at ports 4, 5, 6, 7
PORTD= 0b00000100;
if ( PIND & (1<<PIND4) )
b3 = true;
else
b3 = false;
if ( PIND & (1<<PIND5) )
b6 = true;
else
b6 = false;
if ( PIND & (1<<PIND6) )
b9 = true;
else
b9 = false;
if ( PIND & (1<<PIND7) )
bSharp = true;
else
bSharp = false;
PORTD= 0b00000000;
}
}
// matrix routine end
Das funktioniert auch soweit... leider hab ich aber das Problem das wenn
ich mehrere Tasten in der Horizontale betätige (also zum Beispiel 1,2,3)
alle bits (b1, b2, b3) zurückgesetzt werden obwohl aber das Gegenteil
passieren soll.
Findet jemand den Fehler in meinem Programm... ich hab schon ewig
rumprobiert. Wäre super ;-)
Vielen Dank und Grüße!