极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11916|回复: 6

PS2keyboard库函数.available()总是返回flase,什么原因

[复制链接]
发表于 2015-3-25 11:06:06 | 显示全部楼层 |阅读模式
本帖最后由 Gwei 于 2015-3-25 11:16 编辑

我在模仿freebuf上的
http://bluereader.org/article/10965311
文章做一个硬件键盘记录。
我的连接是正确的;
arduino IDE版本是1.6.1;
键盘是一个PS2接口;
板子型号是UNO;
PS2Keyboard下载最新的2.4版本
http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html

用IDE打开库文件里的example/Simple_Test.pde,编译下载到板子上,发现keyboard.available()总是返回false
[pre lang="arduino" line="1" file="simple_test,pde"]/*  PS2Keyboard library example
  
  PS2Keyboard now requries both pins specified for begin()

  keyboard.begin(data_pin, irq_pin);
  
  Valid irq pins:
     Arduino Uno:  2, 3
     Arduino Due:  All pins, except 13 (LED)
     Arduino Mega: 2, 3, 18, 19, 20, 21
     Teensy 2.0:   All pins, except 13 (LED)
     Teensy 2.0:   5, 6, 7, 8
     Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
     Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
     Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
     Sanguino:     2, 10, 11
  
  for more information you can read the original wiki in arduino.cc
  at http://www.arduino.cc/playground/Main/PS2Keyboard
  or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
  
  Like the Original library and example this is under LGPL license.
  
  Modified by [email protected] on 2010-03-22
  Modified by Paul Stoffregen <[email protected]> June 2010
*/
   
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  5;

PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  Serial.println("Keyboard Test:");
}

void loop() {
  if (keyboard.available()) {
   
    // read the next key
    char c = keyboard.read();
   
    // check for some of the special keys
    if (c == PS2_ENTER) {
      Serial.println();
    } else if (c == PS2_TAB) {
      Serial.print("[Tab]");
    } else if (c == PS2_ESC) {
      Serial.print("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      Serial.print("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      Serial.print("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      Serial.print("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      Serial.print("[Right]");
    } else if (c == PS2_UPARROW) {
      Serial.print("[Up]");
    } else if (c == PS2_DOWNARROW) {
      Serial.print("[Down]");
    } else if (c == PS2_DELETE) {
      Serial.print("[Del]");
    } else {
      
      // otherwise, just print all normal characters
      Serial.print(c);
    }
  }
}
[/code]
有没有人跟我一样呀!!!!
回复

使用道具 举报

发表于 2015-3-25 11:44:20 | 显示全部楼层
建议你用老一点的ide试试  最新的这个可能有点问题

另外检查连线是不是搞反了

我之前做过

http://www.lab-z.com/ps2a/

制作一个PS2键盘记录器
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-25 15:23:58 | 显示全部楼层
zoologist 发表于 2015-3-25 11:44
建议你用老一点的ide试试  最新的这个可能有点问题

另外检查连线是不是搞反了

hi~ zoologist 代码可以编译通过,应该不是IDE的问题吧?刚才仔细检查了一下我的接口和您的blog中的表示是相符的。我想问一个细节,就是我给键盘通电的一瞬间,键盘的提示灯会亮一下,之后就没反映了,这是可能是键盘原因吗?我用的是清华同方的,10年前的货。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-25 17:05:45 | 显示全部楼层
今天下午调试了一下,目前发现是
attachInterrupt(irq_num, ps2interrupt, FALLING);创建的中断有问题!!
UNO版不能接到有频率的时序信号!!
回复 支持 反对

使用道具 举报

发表于 2015-3-25 21:09:40 | 显示全部楼层
Gwei 发表于 2015-3-25 17:05
今天下午调试了一下,目前发现是
attachInterrupt(irq_num, ps2interrupt, FALLING);创建的中断有问题!! ...

什么意思?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-26 19:36:46 | 显示全部楼层
zoologist 发表于 2015-3-25 21:09
什么意思?

应该是我接错线,才错的,这个应该是申请中断的意思,从high降到low就会触发中断。谢谢了 朋友!!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-26 19:37:04 | 显示全部楼层
zoologist 发表于 2015-3-25 21:09
什么意思?

应该是我接错线,才错的,这个应该是申请中断的意思,从high降到low就会触发中断。谢谢了 朋友!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 17:32 , Processed in 0.062322 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表