Datasheet
Library Example
This simple example reads values of the pressed keys on the PS/2 keyboard and
sends them via UART.
unsigned short keydata = 0, special = 0, down = 0;
sbit PS2_Data at PINC.B0;
sbit PS2_In_Clock at PINC.B1;
sbit PS2_Out_Clock at PORTC.B1;
sbit PS2_Data_Direction at DDRC.B0;
sbit PS2_Clock_Direction at DDRC.B1;
void main() {
ACSR.B7 = 1; // Disable analog comparators
SREG.B7 = 0; // Disable all interrupts
UART1_Init(19200);
Ps2_Config(); // Init PS/2 Keyboard on PORTC
Delay_ms(100); // Wait for keyboard to finish
UART1_Write('R'); // Ready
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
//UART1_Write('n'); // uncomment this line
if usart terminal also expects line feed
// for new line transition
}
else if (down && !special && keydata) {
UART1_Write(keydata);
}
}
Delay_ms(10); // debounce
} while (1);
}
370
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6