Folientastatur

Gast #441582
Lesenswert?

Hallo habe meine Folientastatur
(http://www1.conrad.de/conrad/layout2/detail.fh?fh_secondid=b2c709930&layout=layout2&fh_host=www1.conrad.de&fh_eds=%c3%9f&do_fh_search=1&fh_session=%2fscripts%2fwgate%2fzcop_b2c%2f~flN0YXRlPTEyNTUxODc1MTQ%3d&fh_location=%2f%2fb2cconrad_de_b2c%2fde_DE&fh_search=folientastatur&fh_refview=search)
folgendermaßen angeklemmt:
die ersten drei leitungen (Spalten) PORTC0-2
die anderen 4 (Zeilen) an PORTC3-6



Hier das Prog
======================================================================== 
====
void main(void)
{
  ////////////////////////////////////////
  ////  Variablendeklarationen    ////
  ////////////////////////////////////////
  char Zahl;

  Zahl = 0;

  ////////////////////////////////////////
  ////    Portbelegungen      ////
  ////////////////////////////////////////
  DDRA    =  0xff;  //Port A als Ausgang definieren[Display]
  DDRC  |=  0x07;  //Port C0-2 als Ausgang
  DDRC  &=  0x07;  //Port C3-6 als Eingang
  PORTC   |=  0x78;  //enable pull-ups C3-6

  ////////////////////////////////////////
  ////  Displayinitialisierung    ////
  ////////////////////////////////////////
  //lcd_init(LCD_DISP_ON);
  lcd_init(LCD_DISP_ON);
  lcd_clrscr();
  lcd_gotoxy(0,1);
  lcd_puts("Ready");
  lcd_gotoxy(0,0);

while(1)
  {
    ////  Spalte_1  ////
    PORTC |= 0x07;    //Port C0-2 auf HIGH setzen
    PORTC &= 0xFE;    //Port C0 LOW setzen [Spalte 1]

    if( ( PINC & ( 1 << PC3 ) ) == 0 )      //Zeile_1
    {
      Zahl = 1;
      lcd_puts("1");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC4 ) ) == 0 )      //Zeile_2
    {
      Zahl = 4;
      lcd_puts("4");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC5 ) ) == 0 )      //Zeile_3
    {
      Zahl = 7;
      lcd_puts("7");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC6 ) ) == 0 )      //Zeile_4
    {
      Zahl = '*';
      lcd_puts("*");
    }
    _delay_ms(50);

    ////  Spalte_2  ////
    PORTC |= 0x07;    //Port C0-2 auf HIGH setzen
    PORTC &= 0xFD;    //Port C1 LOW setzen [Spalte 2]

    if( ( PINC & ( 1 << PC3 ) ) == 0 )      //Zeile_1
    {
      Zahl = 2;
      lcd_puts("2");
    }
    _delay_ms(50);

    if( ( PINC & ( 1 << PC4 ) ) == 0 )      //Zeile_2
    {
      Zahl = 5;
      lcd_puts("5");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC5 ) ) == 0 )      //Zeile_3
    {
      Zahl = 8;
      lcd_puts("8");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC6 ) ) == 0 )      //Zeile_4
    {
      Zahl = '0';
      lcd_puts("0");
    }
    _delay_ms(50);

    ////  Spalte_3  ////
    PORTC |= 0x07;    //Port C0-2 auf HIGH setzen
    PORTC &= 0xFB;    //Port C2 LOW setzen [Spalte 3]

    if( ( PINC & ( 1 << PC3 ) ) == 0 )      //Zeile_1
    {
      Zahl = 3;
      lcd_puts("3");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC4 ) ) == 0 )      //Zeile_2
    {
      Zahl = 6;
      lcd_puts("6");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC5 ) ) == 0 )      //Zeile_3
    {
      Zahl = 9;
      lcd_puts("9");
    }
    _delay_ms(50);
    if( ( PINC & ( 1 << PC6 ) ) == 0 )      //Zeile_4
    {
      Zahl = '#';
      lcd_puts("#");
    }
    _delay_ms(50);
      }
}
======================================================================== 
=

so wenn ich nun mein ATMega16 damit flashe, dann erscheint die ganze 
zeit nur 2 auf dem Display, als wäre die ganze zeit die taste für 2 
gedrückt....

Danke !
Gast #441707
Lesenswert?

Ja richtig, habe die Tastatur durchgemessen, also da klemmt nichts,
wäre ja auch zu schön bei einer nagelneuen tastatur, aber aufgeklebt 
habe ich sie allerdings auch noch nicht....

woran könnte es denn schätzungsweise noch liegen ?
also die abfrage ist gleich wie bei all den anderen, halt nur 
angepasst....

    if( ( PINC & ( 1 << PC3 ) ) == 0 )      //Zeile_1
    {
      Zahl = 2;
      lcd_puts("2");
    }
    _delay_ms(50);


und sonst änder ich an dem port ja auch nichts....
Gast #441986
Lesenswert?

Warum wartest du nach jedem Pin-Test 50ms ? So wie ich das sehe, wartest 
Du 12*50ms - liest also nur alle 600ms den Tastaturstatus.



schönerer quelltext (wenn nicht nach Anzahl Zeilen bezahlt):

mach mal:

  zahl = -1;
  switch (!PINC)
  {
    case (1 << PC3): Zahl=1; break;
    case (1 << PC4): Zahl=2; break;
    ....
  }
  if (zahl != -1) lcd_put(ord(`0`) + zahl);
#442012
Lesenswert?

antworter wrote:
> schönerer quelltext (wenn nicht nach Anzahl Zeilen bezahlt):

Wenns nach dem geht, würde ich das so machen (Ausserdem bin ich
tippfaul)

char SpaltenPin[] = { 0x01, 0x02, 0x04 );

char Spalte[3][4] = { { 1, 4, 7, '*' },
                      { 2, 5, 8, 0 },
                      { 3, 6, 9, '#' } };

char CharSpalte[3][] = { { "147*" },
                         { "2580" },
                         { "369#" } };

....

    zahl = -1;

    for( i = 0; i < 3; ++i ) {
      PORTC = ~SpaltenPin[i];    // Port C die Spalte auswählen
                                 // Das Schaltet auch unnötigerweise
                                 // die Pullups immer wieder ein,
                                 // aber das macht nichts.

      Index = ( PINC & 0x78 ) >> 3;
      if( Index > 0 ) {
        zahl = Spalte[i][Index];
        lcd_putc( CharSpalte[i][Index] );
      }
      _delay_ms(50);
    }

aber das ist eine andere Geschichte.
#442044
Lesenswert?

> auch sehr schön

nur hats einen (kleinen) Schönheitsfehler.
Es funktioniert so nicht :-)
Ist aber kein Problem, ist leicht behebbar.
Tip: In Index ist jeweils eines von 4 Bit gesetzt
wenn die Taste gedrückt wurde. Das heist aber nicht,
dass das dann die Zahlen von 0 bis 4 ergibt.
Abhilfe: Die Codierarrays auf 16 Einträge erweitern.

Habs auch erst jetzt bei erneutem Durchlesen gemerkt :-)

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren