Hallo

Meine PS/2-Programme für Tastatur und Maus (Anschluss jeweils an PC0 und PC1):
Code:
// PS/2-Schnittstelle am ATMega32                                  1.4.2009 mic
// RP6 liest AT-Tastatur am I2C-Port

// http://www.marjorie.de/ps2/ps2_protocol.htm
// http://www.beyondlogic.org/keyboard/keybrd.htm

#include "RP6RobotBaseLib.h"

uint8_t i, scancode;

int main(void)
{
	initRobotBase();
	DDRC &= ~3; //SDA und SCL sind Eingänge
	PORTC  &= ~3; // ohne interne PullUps (extern sind 4k7 PullUps angeschlossen)

	while(1)
	{
		i=0;
		scancode=0;
		while(PINC & 1); // Warten auf Startbit
		while(!(PINC & 1)); // Ende Startbit
		do
		{
		   while(PINC & 1); // Tastatur bereitet die Daten vor
		   if(PINC & 2) scancode |= (1<<i); // Bit einlesen
		   i++;
		   while(!(PINC & 1)); // gelesen, auf nächstes Bit warten
		}while(i<8);

		while(PINC & 1); // Warten auf Paritybit
		while(!(PINC & 1)); // Ende Paritybit
		while(PINC & 1); // Warten auf Stopbit
		while(!(PINC & 1)); // Ende Stopbit

		writeInteger(scancode, 16);
		writeChar('\n');
	}
	return(0);
}
Code:
// PS/2-Schnittstelle am ATMega32                                  1.4.2009 mic
// RP6 liest PS/2-Maus am I2C-Port

// http://www.marjorie.de/ps2/ps2_protocol.htm
// http://www.beyondlogic.org/keyboard/keybrd.htm
// http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2004/jcc72/index.html

// Hihi: http://www.mikrocontroller.net/topic/130824

#include "RP6RobotBaseLib.h"

#define Clock_Low  	{DDRC |=1; PORTC &=~1;} 	// clock low aktiv
#define Data_Low   	{DDRC |=2; PORTC &=~2;} 	// data low aktiv
#define Clock_High 	{DDRC &=~1; PORTC &=~1;} 	// clock high (Eingang mit PullUp)
#define Data_High  	{DDRC &=~2; PORTC &=~2;} 	// data high (Eingang mit PullUp)
#define Data_Out     {DDRC |=2; PORTC |=2;} 		// data high aktiv
#define Clock_In     (PINC & 1)
#define Data_In      (PINC & 2)

uint8_t i, scancode;

// Send a command to the mouse
// http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2004/jcc72/code.html
void send(uint8_t command)
{

  char parity=0;
  char mask = 0x01;
  parity =  (command & 0x01) ^		//Calculate odd parity
            ((command & 0x02) >> 1) ^ // ich kenne das anders ;)
            ((command & 0x04) >> 2) ^
            ((command & 0x08) >> 3) ^
            ((command & 0x10) >> 4) ^
            ((command & 0x20) >> 5) ^
            ((command & 0x40) >> 6) ^
            ((command & 0x80) >> 7);
  Clock_Low;  	// Pull clock low
  //delay_us(120);
  sleep(2);
  Data_Low;  	// data low
  Clock_High; 	// Release clock
  while(!Clock_In); // wait for clock high
  for (i=0; i<8; i++) {

       while(Clock_In);  // wait for low clock
       //PORTD.1 = !(command & mask); // send inverted data bit to data line
       if(command & mask) Data_Low else Data_Out
       while(!Clock_In);   // wait for clock high
       mask = mask<<1;   // update mask
  }

  while(Clock_In);  // wait for low clock
  //PORTD.1 = parity;	//send parity bit to data line
  if(parity) Data_Low else Data_High
  while(!Clock_In);   // wait for high
  while(Clock_In);  // wait for low clock
  while(!Clock_In);   // wait for clock high

  Data_High;	//release the data line

  while(Data_In); // wait for data go low
  while(!Data_In); // wait for data go hi
}
uint8_t read(void)
{
		uint8_t i, scancode;
		i=0;
		scancode=0;
		while(Clock_In); // Warten auf Startbit
		while(!Clock_In); // Ende Startbit
		do
		{
		   while(Clock_In); // Tastatur bereitet die Daten vor
		   if(Data_In) scancode |= (1<<i); // Bit einlesen
		   i++;
		   while(!Clock_In); // gelesen, auf nächstes Bit warten
		}while(i<8);

		while(Clock_In); // Warten auf Paritybit
		while(!Clock_In); // Ende Paritybit
		while(Clock_In); // Warten auf Stopbit
		while(!Clock_In); // Ende Stopbit
	return(scancode);
}

int main(void)
{
	initRobotBase();
	Clock_High;
	Data_High;
	
		writeString_P("\nBitte Maus bewegen!\n\n");
		send(0xf4);
		mSleep(500);

	while(1)
	{
		writeInteger(read(), 16);
		writeChar('\n');
	}
	return(0);
}
Beide Programme laufen auf meinem RP6 (8MHz-Mega32), sollten aber einfach zu portieren sein. Vielleicht hilft euch das beim Einstieg.

Gruß

mic