Hallo,
ich habe an meinem Atmega 64 eine 3x4 Matrixtastatur angeschlossen. Und
ich habe folgenden Code dafür geschrieben:
PORTC=0x7F;
DDRC=0x70;
#define Z4 PINC.0
#define Z3 PINC.1
#define Z2 PINC.2
#define Z1 PINC.3
#define SP1 PORTC.4
#define SP2 PORTC.5
#define SP3 PORTC.6
keyboard()
{
//Spalte 1
SP1 = 0;
SP2 = 1;
SP3 = 1;
if (Z1 == 0) lcd_putsf("3");
if (Z2 == 0) lcd_putsf("6");
if (Z3 == 0) lcd_putsf("9");
if (Z4 == 0) lcd_putsf("#");
//Spalte 2
SP1 = 1;
SP2 = 0;
SP3 = 1;
if (Z1 == 0) lcd_putsf("2");
if (Z2 == 0) lcd_putsf("5");
if (Z3 == 0) lcd_putsf("8");
if (Z4 == 0) lcd_putsf("0");
//Spalte 3
SP1 = 1;
SP2 = 1;
SP3 = 0;
if (Z1 == 0) lcd_putsf("1");
if (Z2 == 0) lcd_putsf("4");
if (Z3 == 0) lcd_putsf("7");
if (Z4 == 0) lcd_putsf("*");
}
Z1 bis Z4 haben jeweils einen 10k PullUp.
Die Funktion Keyboard rufe ich alle 100ms aus der while(1)-Schleife auf.
Es funktionieren soweit alle Tasten bis auf die 1, da kommt immer die 3.
Stelle ich die Reihenfolge des Codes um z.B. //Splate2, //Spalte1 und
zum schluss //Spalte3 kommt anstelle der 1 eine 2.
Schreibe ich in //Spalte 3
SP3 = 0;
SP1 = 1;
SP2 = 1;
bekomme ich als ausgabe auf dem Display entweder 31 oder 21, jenachdem,
in welcher reihenfolge die //Spalten-Blöcke im Code angeordnet sind.
Soweit ich das überblicke sind auch alle leitungen richtig verbunden und
es liegt auch kein kurzschluss vor.
Vielleicht hat ja einer von euch ne Idee.
Gruß
Olli
Habe unter: http://www.mikrocontroller.net/articles/AVR-Tutorial:_IO-Grundlagen die Lösung gefunden. Das Programm sieht jetzt so aus: keyboard() { SP1 = 1; SP2 = 0; SP3 = 1; #asm nop #endasm if (Z1 == 0) lcd_putsf("2"); if (Z2 == 0) lcd_putsf("5"); if (Z3 == 0) lcd_putsf("8"); if (Z4 == 0) lcd_putsf("0"); SP1 = 0; SP2 = 1; SP3 = 1; #asm nop #endasm if (Z1 == 0) lcd_putsf("3"); if (Z2 == 0) lcd_putsf("6"); if (Z3 == 0) lcd_putsf("9"); if (Z4 == 0) lcd_putsf("#"); SP3 = 0; SP1 = 1; SP2 = 1; #asm nop #endasm if (Z1 == 0) lcd_putsf("1"); if (Z2 == 0) lcd_putsf("4"); if (Z3 == 0) lcd_putsf("7"); if (Z4 == 0) lcd_putsf("*"); } allerdings ist mir unklar wieso ein nop geht aber als ich das mit einem delay versucht habe es nicht funktioniert hat?!
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.