Index: kbd/xtk/code/Makefile
===================================================================
--- kbd/xtk/code/Makefile	(revision 9e3cc0481d2a895c87645ba7df063fc0386ef2f4)
+++ kbd/xtk/code/Makefile	(revision 4fbae10c6c7937b0cd4b763165b385d612b74e88)
@@ -1,14 +1,18 @@
 CC := $(shell { which avr-gcc || which avr-gcc-x86; } 2>/dev/null)
 OBJCOPY := $(shell { which avr-objcopy || which avr-objcopy-x86; } 2>/dev/null)
+AVRDUDE := $(shell { which avrdude || which avrdude-x86; } 2>/dev/null)
 
 keyboard.hex: keyboard.bin
-	$(OBJCOPY) -j .text -j .data -O ihex keyboard.bin keyboard.hex
+	$(OBJCOPY) -j .text -j .data -O ihex $^ $@
 
 keyboard.bin: keyboard.o main.o
-	$(CC) keyboard.o main.o -o keyboard.bin -mmcu=atmega8 -Os
+	$(CC) $^ -o $@ -mmcu=atmega8 -Os
 
-main.o: main.c ../../libs/usart/usart.h ../../libs/ps2_keyboard/ps2_keyboard.h
-	$(CC) -std=c99 -c main.c -mmcu=atmega8 -Os -o main.o -mmcu=atmega8 -Os
+main.o: main.c ../../../libs/ps2_keyboard/ps2_keyboard.h
+	$(CC) -std=c99 -c $< -mmcu=atmega8 -Os -o $@ -mmcu=atmega8 -Os
 
-keyboard.o: ../../libs/ps2_keyboard/ps2_keyboard.c ../../libs/ps2_keyboard/ps2_keyboard.h ../../libs/ps2_keyboard/keymap.h
-	$(CC) -DCALLBACK="callback();" -c ../../libs/ps2_keyboard/ps2_keyboard.c -mmcu=atmega8 -Os -o keyboard.o
+keyboard.o: ../../../libs/ps2_keyboard/ps2_keyboard.c ../../../libs/ps2_keyboard/ps2_keyboard.h ../../../libs/ps2_keyboard/keymap.h
+	$(CC) -DCALLBACK="callback();" -c $< -mmcu=atmega8 -Os -o $@
+
+flash: keyboard.hex
+	$(AVRDUDE) -c usbasp -p atmega8 -Uflash:w:$^
Index: kbd/xtk/code/keyboard.hex
===================================================================
--- kbd/xtk/code/keyboard.hex	(revision 9e3cc0481d2a895c87645ba7df063fc0386ef2f4)
+++ kbd/xtk/code/keyboard.hex	(revision 4fbae10c6c7937b0cd4b763165b385d612b74e88)
@@ -18,42 +18,33 @@
 :100110003F15243F3F3F01A60716051482A513276C
 :1001200006A3A204103F11241FBECFE5D4E0DEBF1A
-:10013000CDBF10E0A0E6B0E001C01D92A637B10728
-:10014000E1F7BFD024C15CCF1F920F920FB60F9280
+:10013000CDBF10E0A0E6B0E001C01D92A736B10728
+:10014000E1F7A5D0E3C05CCF1F920F920FB60F92DC
 :1001500011242F933F934F935F936F937F938F93CC
-:100160009F93AF93BF93EF93FF9382B390E489275C
-:1001700082BB83994EC080916200811108C084992E
-:1001800026C081E0809362001092610027C0209118
-:100190006100283090F4849B0CC03091640081E0B1
-:1001A00090E0022E01C0880F0A94EAF7382B3093B2
-:1001B00064002F5F209361002CC0283021F489E077
-:1001C0008093610026C010926200109261008091BD
-:1001D0006400803F31F481E08093650010926400F8
-:1001E00018C09091640080916500923149F48111AA
-:1001F00004C081E0809360000CC01092600002C0D7
-:10020000882319F01092650004C081E08093630098
-:1002100037D0FF91EF91BF91AF919F918F917F91D7
-:100220006F915F914F913F912F910F900FBE0F9063
-:100230001F901895E82FF0E0EA5DFF4F84919091B0
-:100240006000911180520895809163008823E1F34A
-:1002500010926300809164000895109262001092E1
-:100260006400109261008B98839A85B7886085BF7F
-:1002700085B78B7F85BF8BB780688BBF78940895D7
-:10028000E3DFE82FF0E0EA55FF4FE491809165004D
-:10029000AE2FA295AF70EF70B0E0AA59BF4F21E02A
-:1002A00030E00E2E01C0220F0A94EAF7882329F0CD
-:1002B00020958C9128232C9308958C91822B8C93DC
-:1002C0000895CBDF18BA86E087BB8E9A8FEF9FEF39
-:1002D00064E068BB20E22A95F1F718BA40E24A953B
-:1002E000F1F768BBE0E2EA95F1F718BAF0E2FA95A7
-:1002F000F1F724E030E021503109C0F0AC01022ECA
-:1003000002C0559547950A94E2F740FF02C068BBCA
-:1003100001C018BA40E24A95F1F7C19AE0E4EA95C3
-:10032000F1F718BAF0E7FA95F1F7E5CFE7EDF0E06D
-:100330003197F1F700C0000028E030E0FC01EF70D9
-:10034000FF27EA59FF4F21503109C8F0408150E0A2
-:10035000022E02C0559547950A94E2F740FF02C06D
-:1003600068BB01C018BA40E24A95F1F7C19A40E46F
-:100370004A95F1F718BA40E74A95F1F7E4CF0196AC
-:10038000803191050CF4A5CF8FEF9FEFA2CFF894A9
-:02039000FFCF9D
+:100160009F93AF93BF93EF93FF9383994EC080917A
+:100170006200811108C0849926C081E080936200EA
+:100180001092610027C020916100283090F4849B78
+:100190000CC03091640081E090E0022E01C0880F15
+:1001A0000A94EAF7382B309364002F5F20936100A4
+:1001B0002CC0283021F489E08093610026C0109281
+:1001C00062001092610080916400803F31F481E010
+:1001D000809366001092640018C090916400809132
+:1001E0006600923149F4811104C081E0809360007F
+:1001F0000CC01092600002C0882319F010926600B3
+:1002000004C081E08093630037D0FF91EF91BF91EC
+:10021000AF919F918F917F916F915F914F913F919E
+:100220002F910F900FBE0F901F901895E82FF0E0C0
+:10023000EA5DFF4F84919091600091118052089582
+:10024000809163008823E1F3109263008091640041
+:1002500008951092620010926400109261008B98D1
+:10026000839A85B7886085BF85B78B7F85BF8BB73D
+:1002700080688BBF78940895E3DF109265008091C9
+:100280006600882319F080E88093650008958FEF59
+:1002900080936500DEDF18BA17BA8E9A20E43FEF2C
+:1002A00082B3822782BB809165008F3F09F4FFCF24
+:1002B000CF5F30936500B99A4AE74A95F1F700C0DD
+:1002C000BA9880E38A95F1F788E090E0B998E7E082
+:1002D000F1E03197F1F700C00000B99AFAE7FA951A
+:1002E000F1F700C0C0FF02C0BA9801C0BA9A40E35B
+:1002F0004A95F1F7C6950197009741F7B99887E0BD
+:1003000091E00197F1F700C00000CACFF894FFCF49
 :00000001FF
Index: kbd/xtk/code/main.c
===================================================================
--- kbd/xtk/code/main.c	(revision 9e3cc0481d2a895c87645ba7df063fc0386ef2f4)
+++ kbd/xtk/code/main.c	(revision 4fbae10c6c7937b0cd4b763165b385d612b74e88)
@@ -5,7 +5,7 @@
 #include <util/delay.h>
 
-#include "../../libs/ps2_keyboard/ps2_keyboard.h"
+#include "../../../libs/ps2_keyboard/ps2_keyboard.h"
 
-uint8_t keys[16];
+static uint8_t key;
 
 const uint8_t pcw[128] PROGMEM = {
@@ -25,78 +25,69 @@
 {
 	uint8_t key_code = 0;
-	key_code = read_char(); // TODO this is blocking function
+	key_code = read_char(); // TODO this function is blocking. Can it disturb main?
 
-	uint8_t decode = pgm_read_byte(&(pcw[key_code]));
+	key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;
 	if(release)
-		keys[decode >> 4] &= ~(1 << (decode & 0xF));
-	else
-		keys[decode >> 4] |= 1 << (decode & 0xF);
+		key |= 0x80;
 }
 
 
 int main() {
-  init_keyboard(); 
+	key = 0xFF;
+	init_keyboard(); // PS/2 KBD handler
 
-  // PCW init - configure pins directions
-  PORTB = 0;
-  DDRB = 0x6; // PB1 and PB2 as outputs
+	// PCW init - configure pins directions
+	PORTB = 0;
+	DDRB = 0; // PB2 and PB1 as inputs (floating)
 
-  //debug LED - output
-  DDRD |= (1<<PD6);
+	//debug LED - output
+	DDRD |= (1<<PD6);
 
+	static const int PCLK = 2;
+	static const int PDAT = 4;
 
-  while(1) {
-	for(int idx = -1; idx < 16; idx++)
-	{
-		// send data to PCW
-		
-		// Start pulse
-		PORTB = 4;
-		_delay_us(6);
-		PORTB = 0;
-		_delay_us(6);
-		PORTB = 4;
-		_delay_us(6);
-		PORTB = 0;
-		_delay_us(6);
+	uint8_t k;
+	while(1) {
+#if 0
+		while ((PINB & 2) == 0)
+			; // Wait for PC to be ready to receive data
+#endif
 
-		// Address
-		for(int j = 4; --j >= 0;)
+PORTD ^= (1<<PD6);
+		while(key == 0xFF)
+			; // Wait for data to send
+
+		k = k+1; /*key;*/ // local copy so we can receive another code from PS/2
+		// before we're done sending this one.
+		key = 0xFF;
+
+		// SEND START BIT
+		DDRB |= PCLK; // CLK LOW
+		_delay_us(23);
+		DDRB &= ~PDAT; // DAT HI
+		_delay_us(9);
+
+		for(int i = 0; i < 8; i++)
 		{
-			if(idx & (1<<j))
-				PORTB = 4;
+			DDRB &= ~PCLK; // CLK HI
+			_delay_us(66);
+			DDRB |= PCLK; // CLK LOW
+			_delay_us(23);
+			if (k & 1)
+				DDRB &= ~PDAT;
 			else
-				PORTB = 0;
+				DDRB |= PDAT;
 
-			// Clock
-			_delay_us(6);
-			PORTB |= 2;
-			_delay_us(12);
-			PORTB = 0;
-			_delay_us(21);
+			_delay_us(9);
+
+			k >>= 1;
 		}
 
-		// One "empty" clock cycle
-		_delay_us(21 + 33);
+		DDRB &= ~PCLK; // CLK HI
+		_delay_us(66);
 
-		// Data
-		for(int j = 8; --j >= 0;)
-		{
-			if (keys[idx & 0xF] & (1 << j)) 
-				PORTB = 4;
-			else
-				PORTB = 0;
+	}
 
-			// Clock
-			_delay_us(6);
-			PORTB |= 2;
-			_delay_us(12);
-			PORTB = 0;
-			_delay_us(21);
-		}
-	}
-  }
-  
-  return 0;
+	return 0;
 }
 
