en.radzio.dxp.pl

Typical computer keyboard with PS2 can be easy connected to microcontroller system. On this page I show an example of connecting PC keyboard to Atmel AVR MCU. Example software is written in C language and can be compiled in avr-gcc compiler.

Pinout of PS2 keyboard connector :

ps2 keyboard

 

Data between keyboard and computer is transmitting by two wire synchronous interface (CLK and DATA lines). If data are transmitted from keyboard, clock signal is generated by keyboard. Frequency of this signal is between 20 and 30 kHz (this is not standard). Data frame consist with start bit, eight data bits, parity bit and stop bit.

pc at keyboard

Reading data is easier realized in interrupts from falling edge on CLK line. Schematic of interfacing keyboard to MCU :

pc keyboard

 

Example program which read pressed key scan code  for AVR microcontroller (ATMega16).

Download file :
atkeyboard.h
atkeyboard.c

scancodes.h

 

 
(c) Radosław Kwiecień