arduino의 ps/2 keyboard

2519 단어 ps2USBArduino

개요



arduino leonardo에 ps/2 키보드를 연결하고 usb 키보드를 에뮬레이트해 보았다.

사진





회로도





샘플 코드


#include "ps2.h"

#define PS2_TAB             9
#define PS2_ENTER           13
#define PS2_BACKSPACE       127
#define PS2_ESC             27
#define PS2_INSERT          0
#define PS2_DELETE          127
#define PS2_HOME            0
#define PS2_END             0
#define PS2_SCROLL          0
PS2 kbd(6, 5);
char key[140] = {
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, PS2_TAB, '`', 0,
    0, 0, 0, 0, 0, 'q', '1', 0,
    0, 0, 'z', 's', 'a', 'w', '2', 0,
    0, 'c', 'x', 'd', 'e', '4', '3', 0,
    0, ' ', 'v', 'f', 't', 'r', '5', 0,
    0, 'n', 'b', 'h', 'g', 'y', '6', 0,
    0, 0, 'm', 'j', 'u', '7', '8', 0,
    0, ',', 'k', 'i', 'o', '0', '9', 0,
    0, '.', '/', 'l', ';', 'p', '-', 0,
    0, 0, '\'', 0, '[', '=', 0, 0,
    0, 0, PS2_ENTER, ']', 0, '\\', 0, 0,
    0, 0, 0, 0, 0, 0, PS2_BACKSPACE, 0,
    0, '1', 0, '4', '7', 0, 0, 0,
    '0', '.', '2', '5', '6', '8', PS2_ESC, 0,
    0, '+', '3', '-', '*', '9', PS2_SCROLL, 0,
    0, 0, 0, 0
};
void kbd_init()
{
    char ack;
    kbd.write(0xff);
    ack = kbd.read();
    ack = kbd.read();
}
void setup()
{
    Serial.begin(115200);
    while (!Serial);
    Serial.println("Start");
    kbd_init();
    Keyboard.begin();
    Serial.println("OK");
}
void loop()
{
    unsigned char code;
    for ( ; ; )
    {
        code = kbd.read();
        code = key[code];
        Serial.println(code, HEX);
        Keyboard.print((char) code);
        code = kbd.read();
        code = kbd.read();
    }
}

좋은 웹페이지 즐겨찾기