/* BIT BANG PS2 for atmega640 -connection according to SPI -------------LOOKING AT THE PLUG------------------- ------------------------------- PIN 1->| o o o | o o o | o o o | \_____________________________/ PIN # USAGE 1 DATA 2 COMMAND 3 N/C (9 Volts unused) 4 GND 5 VCC 6 ATT 7 CLOCK 8 N/C 9 ACK ----NOTES-- *> 0x5A(by controller) to say "here comes the data". *> bite 1. header. (should possibly put test on this byte to detect unplugging of controller.) ie if (temp==0x73) */ #ifndef F_CPU #define F_CPU 14745600UL // or whatever may be your frequency #endif #include #include #include #define PSdata 3 // PB3 #define PScommand 2 // PB5 #define PSclock 1 // PB2 #define PSattention 0 // PB6 #define sbi(x,y) x|=(1< 254){ cnt=0;} } } int main(void) { DDRC=0XFF; // PSx controller I/O pin setup: sbi(DDRB, PB1); // clock. output. (blue) cbi(DDRB, PB3); // data. input. (brown) sbi(PORTB, PB3); // enable pullup resistor cbi(DDRB, PB4); // acknolage. input. (green) sbi(PORTB, PB4); // enable pullup resistor sbi(DDRB, PB2); // command. output. (orange) sbi(DDRB, PB0); // attention. output. (yellow) int_PS2inanalougemode(); short int temp, data0, data1, data2, data3, data4, data5, i ,debounceSelect; while(1) { sbi(PORTB, PScommand); // start communication with PSx controller sbi(PORTB, PSclock); cbi(PORTB, PSattention); gameByte(0x01); // bite 0. header. temp = gameByte(0x42); // bite 1. header. (should possibly put test on this byte to detect unplugging of controller.) gameByte(0x00); // bite 2. header. data0 = gameByte(0x00); // bite 3. first data bite. data1 = gameByte(0x00); // bite 4. data2 = gameByte(0x00); // bite 5. data3 = gameByte(0x00); // bite 6. data4 = gameByte(0x00); // bite 7. data5 = gameByte(0x00); // bite 8. _delay_us(1); sbi(PORTB, PScommand); // close communication with PSx controller _delay_us(1); sbi(PORTB, PSattention); // all done. PORTC=data5; } }