Mikroelektronika MIKROE-742 데이터 시트
Library Example
This simple example reads values of the pressed keys on the PS/2 keyboard and
sends them via UART.
sends them via UART.
program PS2_Example;
var keydata, special, down : byte;
var PS2_Data : sbit at PINC.B0;
PS2_Clock_Input :
sbit at PINC.B1;
PS2_Clock_Output :
sbit at PORTC.B1;
PS2_Data_Direction :
sbit at DDRC.B0;
PS2_Clock_Direction :
sbit at DDRC.B1;
begin
UART1_Init(19200); // Initialize UART module at 19200 bps
Ps2_Config(); // Init PS/2 Keyboard
Delay_ms(100); // Wait for keyboard to finish
Delay_ms(100); // Wait for keyboard to finish
UART1_Write('R'); `
// Ready
while TRUE do
// Endless loop
begin
if Ps2_Key_Read(keydata, special, down) then
// If data
was read from PS/2
begin
if (down <> 0) and (keydata = 16) then // Backspace read
begin
UART1_Write(0x08); // Send
Backspace to USART terminal
end
else if (down <> 0) and (keydata = 13) then
// Enter read
begin
UART1_Write(10); // Send
carriage return to usart terminal
UART1_Write(13); //
Uncomment this line if usart terminal also expects line feed
// for new line transition
end
else if (down <> 0) and (special = 0) and (keydata <>
0)
then
// Common key read
begin
UART1_Write(keydata); // Send key to usart terminal
end;
end;
Delay_ms(10); // Debounce period
end;
end.
318
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6