Atmega 32 <=> PS2 Tastatur Resend

OP #2311652
Lesenswert?

Hallo!

Ich bin gerade dabei das ich auf einen Atmega 32 über PS2 
Tastaturbefehle einlese und diese als Hexwert auf meinen LCD ausgebe.
Dies funktioniert schon ganz gut.

Jetzt will ich noch einen resend Befehl zur Tastatur senden wenn das 
parity bit nicht stimmt.
Jedoch sendet mir die Tastatur 0xFE zurück. Also das sie mit den Befehl 
nichts anfangen kann!?

Hier die zwei Funktionen die ich benutze:
(der Funktion sendKB übergebe ich 0xFE)
(der ganze Code befindet sich im Anhang)
1
/************************************************************************/
2
/* This function initialize send data to the keyboard  
3
/************************************************************************/
4
void sendKb_init() {
5
  send = 1;
6
  // Port D PD3 and PD6 output enable
7
  DDRD |= (1<<PD3);  
8
  DDRD |= (1<<PD6);
9
  
10
  // clock min 100µs low
11
  PORTD &= ~(1<<PD3); 
12
  _delay_us(100); //min100µs
13
  
14
  // data low
15
  PORTD &= ~(1<<PD6);
16
  _delay_us(50);
17
  
18
  // clock high
19
  PORTD |= (1<<PD3);
20
  
21
  // wait for clock low (interrupt) from keyboard
22
  // Port D PD3 Input and pullup resistor enable
23
  DDRD &= ~(1<<PD3);  
24
  PORTD |= (1<<PD3);
25
  send_init = 1;  
26
}
27

28
/************************************************************************/
29
/* This function send data to the keyboard  
30
/************************************************************************/
31
void sendKb(uint8_t data) {  
32
  if (sendBit >= 0 && sendBit <=7) {
33
    // send Data
34
    uint8_t dataBit = (data>>sendBit) & 1;
35
    if (dataBit == 1) {
36
      PORTD |= (1<<PD6);
37
    }
38
    else {
39
      PORTD &= ~(1<<PD6);
40
    }
41
    sendBit++; //increment sendBit    
42
  }
43
  else if (sendBit == 8) {
44
    //send parity    
45
    if (parity_odd_bit(data) == 1) {
46
      PORTD |= (1<<PD6);
47
    }
48
    else {
49
      PORTD &= ~(1<<PD6);
50
    }
51
    sendBit++; //increment sendBit
52
  }
53
  
54
  else if ((sendBit >= 9) && (waitACK == 0)) {
55
    //set data to input
56
    DDRD &= ~(1<<PD6);
57
    //set waitACK
58
    waitACK = 1;
59
  }  
60
  
61
  else if (waitACK == 1) { //wait for ACK from the keyboard
62
    uint8_t dataBit = (PIND & (1<<PIND6)) >> PIND6; //save dataBit from kb
63
    //if data is zero then the keyboard ack
64
    if (dataBit == 0) {
65
      sendBit = 0;
66
      send = 0;
67
      send_init = 0;
68
      waitACK = 0;
69
    }    
70
  }  
71
}

Hat jemand eine Idee was ich da falsch mache?

godi
Angehängte Dateien:

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