?? demo.c
字號:
/*
* Project name:
DEMO (Simple demonstration of the PS2 Library functions)
* Copyright:
(c) MikroElektronika, 2008.
* Description:
This code demonstrates communication with ps/2 keyboard.
Scan codes that represent key are send to PC via UART-0.
* Test configuration:
MCU: LPC2148
Dev.Board: EasyARM
Oscillator: 12.0 MHz (cclk = 60.0 MHz, Fcco = 240.0 MHz)
Ext. Modules: - PS/2 Keyboard
SW: KEIL uVision3 v3.62c
* NOTES:
- Place Pull-up Jumper J16 at PORT0[15..8]
- Place jumpers J6 and J7 in left position to connect PS/2 keyboard
lines to P1.16 and P1.17
- Be sure to turn ON the switches for RS232-0 to connect UART lines
to RS232-0 output (Switch SW1)
- Start UART terminal adjusted to 38400 bps, 8 bit, no parity
*/
#include <LPC214X.H>
#include "ps2.h"
#include "Serial.h"
#include "Utility.h"
unsigned char
raw_data[16],
raw_pos,
raw_buff[64],
raw_count,
rd_count;
unsigned long
n;
int main (void)
{
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
PINSEL2 |= 0x00000030;
DelayProc(0.2 * CCLOCK);
// Init UART0
UART0_init(38400/*bps*/, 15000/*kHz*/, length_8_bit, stop_bit_1, parity_disable, parity_odd);
UART0_sendstring ("START\n");
// Init PS/2 Keyboard
Ps2_Init(&IOPIN1, 17/*CLK*/, 16/*DATA*/);
UART0_sendstring ("Ps2_Init().\n");
// Delay 100ms, Wait for keyboard to finish
DelayProc(0.250 * CCLOCK);
UART0_sendstring ("DelayProc().\n");
// Set Keyboard Delay and Typematic Rate
Ps2_Adjust_Rate(TR_Delay_750ms, TR_Rate_10);
UART0_sendstring ("Ps2_Adjust_Rate().\n");
// Display Key-codes on Terminal window
rd_count = 0;
raw_count = 0;
do
{
Ps2_Data_Read(&raw_pos, raw_data);
if (raw_pos != 0)
{
for (n=0; n<raw_pos; n++)
raw_buff[raw_count++] = raw_data[n];
}
else
{
rd_count++;
if ((raw_count != 0) && (rd_count > 50))
{
for (n=0; n<raw_count; n++)
{
UART0_WriteNum ("0x", raw_buff[n]);
UART0_sendchar (' ');
}
UART0_sendstring ("\n");
rd_count = 0;
raw_count = 0;
}
}
DelayProc(1E-03 * CCLOCK);
} while (1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -