unsigned short keydata = 0, special = 0, down = 0;
sbit PS2_Data at PINC.B0;
sbit PS2_Clock_Input at PINC.B1;
sbit PS2_Clock_Output at PORTC.B1;
sbit PS2_Data_Direction at DDRC.B0;
sbit PS2_Clock_Direction at DDRC.B1;
void main() {
//PS_2_Data_Direction = 0; //Data pin as input
DDRC = 0x02; //PORTC_1 as output
UART1_Init(9600); // Initialize UART module at 19200 bps
Ps2_Config(); // Init PS/2 Keyboard
Delay_ms(100); // Wait for keyboard to finish
do {
if (Ps2_Key_Read(&keydata, &special, &down)) {
if (down && (keydata == 16)) {// Backspace
UART1_Write(0x08);
}
else if (down && (keydata == 13)) {// Enter
UART1_Write('r'); // send carriage return to usart terminal
//Usart_Write('n'); // uncomment this line if usart terminal also expects line feed
// for new line transition
}
else if (down && !special && keydata) {
if (down && !special && keydata) {
UART1_Write(keydata); // and send data via UART
}
}
}
Delay_ms(10); // debounce
} while (1);
}