<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TS &#187; 键盘</title>
	<atom:link href="http://www.daihuaxin.com/index.php/tag/%e9%94%ae%e7%9b%98/feed" rel="self" type="application/rss+xml" />
	<link>http://www.daihuaxin.com</link>
	<description>崩溃后重生的The.Soloist开始新的blogging生涯</description>
	<lastBuildDate>Sat, 19 Jun 2010 20:15:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>从零开始，在FPGA上使用PS2键盘</title>
		<link>http://www.daihuaxin.com/index.php/document/ps2-keyboard-on-fpga</link>
		<comments>http://www.daihuaxin.com/index.php/document/ps2-keyboard-on-fpga#comments</comments>
		<pubDate>Sun, 16 Nov 2008 06:13:42 +0000</pubDate>
		<dc:creator>The.Soloist</dc:creator>
				<category><![CDATA[文档]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[ps2]]></category>
		<category><![CDATA[键盘]]></category>
		<category><![CDATA[驱动]]></category>

		<guid isPermaLink="false">http://www.daihuaxin.com/?p=89</guid>
		<description><![CDATA[热度:

声明：全文属原创，转载请注明出处。文中引用的图片均有原地址链接。
这两天因为项目需要，得做一个ps2键盘和FPGA板的接口程序，google了一下，再参考些别人的代码，慢慢明白了PS2键盘的工作原理，自己动手写了个verilog模块用来驱动键盘。因为项目的重心不在键盘上，所以模块写得很简单，只驱动了几个键并且没考虑多键同时按下和特殊按键的情况，留待以后再完善吧。
<span class="readmore"><a href="http://www.daihuaxin.com/index.php/document/ps2-keyboard-on-fpga" title="从零开始，在FPGA上使用PS2键盘" target="_blank">阅读全文——共832字</a></span>]]></description>
			<content:encoded><![CDATA[
<table>
<tr cellpadding=0><td>热度:</td><td cellpadding=0><img src='http://www.daihuaxin.com/wp-content/plugins/statpresscn/images/sun.gif' width=10 height=10 border=0 /></td><td cellpadding=0><img src='http://www.daihuaxin.com/wp-content/plugins/statpresscn/images/sun.gif' width=10 height=10 border=0 /></td><td cellpadding=0><img src='http://www.daihuaxin.com/wp-content/plugins/statpresscn/images/sun.gif' width=10 height=10 border=0 /></td><td cellpadding=0><img src='http://www.daihuaxin.com/wp-content/plugins/statpresscn/images/sun.gif' width=10 height=10 border=0 /></td><td cellpadding=0><img src='http://www.daihuaxin.com/wp-content/plugins/statpresscn/images/sun_dark.gif' width=10 height=10 border=0 /></td></tr>
</table>
<p><p>声明：全文属原创，转载请注明出处。文中引用的图片均有原地址链接。</p>
<p>这两天因为项目需要，得做一个ps2键盘和FPGA板的接口程序，google了一下，再参考些别人的代码，慢慢明白了PS2键盘的工作原理，自己动手写了个verilog模块用来驱动键盘。因为项目的重心不在键盘上，所以模块写得很简单，只驱动了几个键并且没考虑多键同时按下和特殊按键的情况，留待以后再完善吧。</p>
<p>先从PS2键盘的工作原理说起吧。</p>
<p>PS2键盘和主机通信的方式很简单，PS2接口上有6根线，2根是没用的，1根电源，1根地，另外两根是我们要考虑的。其中一根是时钟，对于我那个项目而言，因为不用考虑诸如设置键盘重复频率，numlock灯之类的问题，只需要读取键盘发来的数据，所以这个时钟就由键盘提供。这个时钟频率约在10~16.7kHz之间。另一根是数据线，每按下或松开按键时就会有1~3组不等的数据从数据线传过来，因此FPGA要做的就是按键盘时钟将这些数据接收并解码成所需的格式。</p>
<p>发送回的数据格式大致如下：</p>
<p>每组数据为11位，包括1位起始位，8位数据位，1位奇偶校验位（奇校验）和1位停止位。起始位永远为0，停止位永远为1。8位数据为按键的代码，按键和代码的对应关系参见以下地址：</p>
<p><a href="http://www.computer-engineering.org/ps2keyboard/scancodes2.html">http://www.computer-engineering.org/ps2keyboard/scancodes2.html</a></p>
<p>注意其中的make和break的区别。make是当按下键的时候发送的代码，break是抬起键的时候发送的代码。对于有多个代码的键，每一个代码都要按照上述格式发送，这就是为什么会有1~3组不等的数据发回的原因。</p>
<p>收到代码之后，用一个case就可以识别不同的键并实现任意形式的转换（转成ASCII码，控制信号等等等等）。</p>
<p>目前我只能做到识别抬起键，还不能做到识别抬起哪个键，不过这个程序改起来应该也不会太复杂，等到有时间了改一改。</p>
<p>代码可以去<a href="http://www.opencores.org">www.opencores.org</a>下载，找到bu pacman项目就好了</p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati 标签: <a class='technorati-link' href='http://technorati.com/tag/FPGA' rel='tag' target='_blank'>FPGA</a>, <a class='technorati-link' href='http://technorati.com/tag/ps2' rel='tag' target='_blank'>ps2</a>, <a class='technorati-link' href='http://technorati.com/tag/%E9%94%AE%E7%9B%98' rel='tag' target='_blank'>键盘</a>, <a class='technorati-link' href='http://technorati.com/tag/%E9%A9%B1%E5%8A%A8' rel='tag' target='_blank'>驱动</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.daihuaxin.com/index.php/document/ps2-keyboard-on-fpga/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
