/* PS/2 KEYBOARD INTERFACE FOR AVR v1.1 Written by Jan Sixta, originaly from 13.01.2011 jan.16@seznam.cz http://jan16.czela.net/ ICQ:225-664-188 Skype: sixta16 Software interface for standard PS/2 (PC) keyboards Including basic functions: - Software emulated PS/2 BUS using one external interrupt (INT0) and one I/O pin as a DATA line - Processing functions for decoding received data packets - A functions for translation from the SCAN-CODE to ASCII Change log: Version 1.1, from 28.07.2011 - two decoding tables, for standard and extended keys - Flag PS2_EXT now only for internal use - Added a flag clearing function - New ReadKey function for easier use - New KeyPressed function for detecting if there was made a press This library is for non-comercial use only. Without any warranty. */ volatile unsigned char PS2_Bit; //Bit counter volatile unsigned char PS2_BitShift; volatile unsigned char PS2_Data; //keybd DATA register volatile unsigned char PS2_ASCII; //ASCII code of received key press //PS2 Flag and Attribute register volatile unsigned char PS2_Flag; //b0 - new key down event - When key down event occur, this flag is set. //b1 - new key up event - When key up event occur, this flag is set. //b2 - control code received - Control code like 0xAA, 0xFF, 0xEE was received. //b3 - //b4 - //b5 - key up event - not a public flag, attribute, means key was released //b6 - extended key code - not a public flag, set when extended key indentifier was recvd //b7 - data received - not a public flag, set when new data received in PS2_Data #define PS2_EVDOWN 0 #define PS2_EVUP 1 #define PS2_CTRL 2 #define PS2_KEYUP 5 #define PS2_EXT 6 #define PS2_RXD 7 //PS2 Bus line DATA signal #define PS2_D_PIN PIND #define PS2_D_PORT PORTD #define PS2_D_DDR DDRD #define PS2_D PD4 /* Standard keys have got classic ASCII codes. Other keys like F1..F12, Arrows, Shift, etc. have selected ASCII numbers, as listed below. The Extended Keys has got special decoding table and they are given codes 128 and over, where there are none ASCII symbols writable by any standard key. It means, that the given ASCII codes of Extended Keys do not collide with standard keys. Due to some Extended Keys have got same codes as a standard ones, we must use two separate decoding tables. */ #define KEY_UP 128 #define KEY_DOWN 129 #define KEY_LEFT 130 #define KEY_RIGHT 131 unsigned char Scan2ASCII[] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0,81, 0, 0, 0, 0,90,83,65,87, 0, 0, 0,67,88,68,69, 0, 0, 0, 0,32,86,70,84,82, 0, 0, 0,78,66,72,71,89, 0, 0, 0, 0,77,74, 85, 0, 0, 0, 0, 0,75,73,79, 0, 0, 0, 0,46,47,76,59,80,45, 0, 0, 0,21, 0,91,61, 0, 0, 0, 0,13,93, 0,92, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0,49, 0,52,55, 0, 0, 0,48,44,50,53,54,56,27, 0, 0,43,51,45,42,57, 0, 0, 0, 0, 0, 0}; unsigned char Scan2ASCIIspc[] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_LEFT, 0, 0, 0, 0, 0, 0, KEY_DOWN, 0, KEY_RIGHT, KEY_UP, 0, 0 }; //External INT0, reacting on the positive slope of CLOCK signal //on the PS/2 BUS. ISR(INT0_vect) { if ((PS2_Bit==0) && (PS2_D_PIN & (1<> 1) | ((PS2_D_PIN & (1<