電腦鍵盤(pán)工作原理
輔助設備(指 鍵盤(pán)) 檢查 時(shí)鐘線(xiàn) ,如果時(shí)低電平,禁止發(fā)送數據
The auxiliary device checks the 'data' line. If the line is inactive, the controller receives data from the system.
設備檢查數據線(xiàn),如果是 低電平,那么控制器從系統接收數據
The auxiliary device checks the 'clock' line during the transmission at intervals not exceeding 100 microseconds. If the device finds the system holding the 'clock' line inactive, the transmission is terminated. The system can terminate transmission anytime during the first 10 clock cycles.
設備在傳輸過(guò)程中 檢查 時(shí)鐘 線(xiàn) 間隔不超過(guò)100us。 如果設備發(fā)現 主機系統 將電平拉低,就終止傳輸。 在傳輸過(guò)程的前10個(gè)時(shí)鐘周期的任何時(shí)候,主機系統可以中止傳輸。
A final check for terminated transmission is performed at least 5 microseconds after the 10th clock.
終止傳輸的最后一個(gè)檢查 要持續至少5us
The system can hold the 'clock' signal inactive to inhibit the next transmission.
系統拉低時(shí)鐘線(xiàn),將禁止下一次傳輸
The system can set the 'data' line inactive if it has a byte to transmit to the device. The 'data' line is set inactive when the start bit (always 0) is placed on the 'data' line.
系統如果有一個(gè)字節要傳輸給設備,可以拉低數據線(xiàn)。當開(kāi)始位(總是0)放置到數據線(xiàn)時(shí),數據線(xiàn)被拉低。
The system raises the 'clock' line to allow the next transmission.
系統拉高時(shí)鐘將允許下一次傳輸
Host-to-Device主機到設備的通信
First of all, the PS/2 device always generates the clock signal.
首先,PS/2設備總是產(chǎn)生時(shí)鐘信號
If the host wants to send data, it must first put the Clock and Data lines in a "Request-to-send" state as follows:
如果主機想發(fā)送數據,它必須先將時(shí)鐘線(xiàn)和數據線(xiàn)設置成"Request-to-send"狀態(tài):
1) Inhibit communication by pulling Clock low for at least 100 microseconds.
拉低時(shí)鐘線(xiàn)至少100us來(lái)禁止通信
2) Apply "Request-to-send" by pulling Data low, then release Clock.
拉低數據線(xiàn),請求 "Request-to-send", 然后釋放時(shí)鐘 .
The device should check for this state at intervals not to exceed 10 milliseconds.
設備應該在不超過(guò)10ms(注意,是毫秒)的間隔內就要檢查一次這個(gè)狀態(tài)。
When the device detects this state, it will begin generating Clock signals and clock in eight data bits and one stop bit.
當設備檢測到這個(gè)狀態(tài),它將開(kāi)始產(chǎn)生時(shí)鐘信號,
The host changes the Data line only when the Clock line is low, and data is read by the device when Clock is high.
只有當時(shí)鐘線(xiàn) 為低的時(shí)候,主機才可以改變數據線(xiàn)(也就是將數據寫(xiě)入到數據線(xiàn))。數據將在時(shí)鐘為高電平的時(shí)候 被 設備讀取。
After the stop bit is received, the device will acknowledge the received byte by bringing the Data line low and generating one last clock pulse.
在收到停止位之后,設備將通過(guò)拉低數據線(xiàn),生成最后一個(gè)時(shí)鐘脈沖 來(lái) 應答收到的字節
If the host does not release the Data line after the 11th clock pulse, the device will continue to generate clock pulses until the the Data line is released (the device will then generate an error.)
在第11個(gè)時(shí)鐘脈沖之后,如果主機并沒(méi)有釋放數據線(xiàn),設備將繼續產(chǎn)生時(shí)鐘脈沖,直到數據線(xiàn)被釋放(然后 設備將產(chǎn)生一個(gè)錯誤)
The host may abort transmission at time before the 11th clock pulse (acknowledge bit) by holding Clock low for at least 100 microseconds.
在第11個(gè)脈沖之前(回應位),主機可以隨時(shí)中止傳輸,只要拉低時(shí)鐘持續100us即可
|
T9 == Time from inactive to active CLK transition, used to time when the auxiliary device samples DATA

FreeScale(Moto)提供的時(shí)序圖
主機到鍵盤(pán)的數據傳輸
1.主機 通過(guò)拉低 時(shí)鐘線(xiàn) 來(lái) 啟動(dòng)一個(gè)主機到鍵盤(pán)的數據傳輸。大約35us后,主機拉低數據線(xiàn)
。這個(gè)事件序列 就是 通知 鍵盤(pán),主機要傳輸一個(gè)命令了。在數據信號的下降沿大約 125us 后 時(shí)鐘信號釋放,就被鍵盤(pán)內部的上拉電阻拉為高電平 。
2. 在時(shí)鐘信號的上升沿 約 1ms ,數據傳輸開(kāi)始。這個(gè)期間,數據線(xiàn)保持低電平。鍵盤(pán)拉低時(shí)鐘線(xiàn),clocking in the low data line. 這個(gè)就做傳輸的起始位。
3. 鍵盤(pán)用時(shí)鐘驅動(dòng) 8個(gè)數據位從主機傳輸到自己這邊。 這個(gè)時(shí)鐘有50%的占空比(duty cycle).高電平和低電平的時(shí)間都在30~50us之間。主機在每個(gè)周期的低電平的時(shí)候改變數據線(xiàn)上的數據。在每個(gè)時(shí)鐘的上升沿5~25us之后鍵盤(pán) 開(kāi)始從數據線(xiàn)上取樣,取出主機發(fā)來(lái)的數據。
4.數據位之后是一個(gè)奇偶校驗位(采用奇校驗)
5.最后是停止位
6.如果鍵盤(pán)讀到一個(gè)高電平的停止位,鍵盤(pán)就在 取樣停止位的那個(gè)時(shí)鐘的下降沿 之后的低電平期間 拉低數據線(xiàn)。這個(gè)行為叫做 鍵盤(pán)給主機的應答信號。
鍵盤(pán)拉高時(shí)鐘之后,也拉高數據線(xiàn)。
7.在收到一個(gè)字節后,鍵盤(pán)對接收的數據執行一個(gè)奇偶校驗。如果奇偶校驗錯誤,或者接收的數據無(wú)法識別為有效的命令,那么鍵盤(pán)請求重新發(fā)送(發(fā)送0xFE給主機)

1. 鍵盤(pán)發(fā)送數據前,首先必須讓時(shí)鐘 和數據線(xiàn)都在鍵盤(pán)內部的上拉電阻作用下 拉成高電平。然后鍵盤(pán)拉低數據線(xiàn),5-25us之后,鍵盤(pán)拉低時(shí)鐘線(xiàn)。在時(shí)鐘的下降沿,開(kāi)始傳輸起始位The falling edge of the clock line clocks in the transfer’s start
bit.
2. 鍵盤(pán)用時(shí)鐘驅動(dòng) 8個(gè)數據位到主機。 這個(gè)時(shí)鐘有50%的占空比(duty cycle).高電平和低電平的時(shí)間都在30~50us之間。鍵盤(pán)在每個(gè)周期的高電平的時(shí)候改變數據線(xiàn)上的數據。這個(gè)改變出現在時(shí)鐘的上升沿的5us后 和 下降沿的5us前。鍵盤(pán)的數據在時(shí)鐘的下降沿被鎖存進(jìn)主機。
3.數據位之后是一個(gè)奇校驗位
4.最后是停止位。在時(shí)鐘的下降沿 0~50us之間 主機拉低時(shí)鐘 來(lái)鎖存停止位。這就告訴鍵盤(pán)主機現在忙,不能在接收 其他的鍵盤(pán)傳輸數據。在處理完接收的數據,準備好接收下一個(gè)數據之前,主機釋放時(shí)鐘。
6.在鍵盤(pán)傳輸數據到主機的過(guò)程中,主機任何時(shí)候都可以中斷這個(gè)傳輸,發(fā)送一個(gè)命令到鍵盤(pán)。主機拉低時(shí)鐘和數據線(xiàn) 即可中止傳輸。所以,鍵盤(pán)在時(shí)鐘為 低電平的時(shí)候必須取樣數據線(xiàn)。(無(wú)論什么時(shí)候輸出高數據位的時(shí)候)。在產(chǎn)生時(shí)鐘的上升沿時(shí),必須讀取時(shí)鐘。
在任何時(shí)候發(fā)現這兩個(gè)條件不滿(mǎn)足,就拉高時(shí)鐘和數據線(xiàn),放棄這次傳輸,并準備從 主機接收命令。

Moto 香港公司的 Derek Lau
當時(shí)鐘 高電平是,發(fā)送給主機的數據被主機讀取。在空閑狀態(tài),時(shí)鐘和數據線(xiàn)都被拉為高電平。主機 拉低 時(shí)鐘最少100ms(?還是us)開(kāi)始發(fā)送數據給鍵盤(pán):
1.主機等待,直到?jīng)]有外部設備傳輸被處理
2.主機 拉低時(shí)鐘
3.主機拉低數據作為開(kāi)始位
4 .主機釋放時(shí)鐘
5.設備拉低時(shí)鐘
6.主機發(fā)送數據
7.設備釋放時(shí)鐘,讀取數據
8.設備檢查時(shí)鐘線(xiàn),如果時(shí)鐘為低,中止傳輸
9.重復 5-7步,發(fā)送 數據1-到數據0,以及 奇校驗位
10. 設備拉低時(shí)鐘
11. 主機釋放數據
12.設備時(shí)鐘時(shí)鐘
13.設備讀取數據線(xiàn),想得到停止位,如果數據線(xiàn)為低(不是停止位),產(chǎn)生錯誤
14.設備拉低 時(shí)鐘和數據線(xiàn)
15.設備釋放 時(shí)鐘和數據線(xiàn)

從設備發(fā)送到主機的數據,在時(shí)鐘的下降沿被讀取。在發(fā)送數據前,設備檢查通過(guò)檢測時(shí)鐘信號為高來(lái)得知 主機是否貯備好:
1.鍵盤(pán)(設備)等待時(shí)鐘為高(約50ms?us)
2.如果數據為 低,終止
3.鍵盤(pán) 發(fā)送數據
4.鍵盤(pán)拉低時(shí)鐘為低
5.鍵盤(pán)釋放時(shí)鐘為高
6.鍵盤(pán) 讀取時(shí)鐘線(xiàn),如果時(shí)鐘為低,中止傳輸
7.重復 4-6步,傳輸數據0-數據7,
DIY機械鍵盤(pán)相關(guān)社區:機械鍵盤(pán)DIY
評論