<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于FPGA的PS/2鼠標(biāo)接口設(shè)計(jì)方法及其應(yīng)用

          基于FPGA的PS/2鼠標(biāo)接口設(shè)計(jì)方法及其應(yīng)用

          作者: 時(shí)間:2012-02-08 來源:網(wǎng)絡(luò) 收藏

            如圖6,當(dāng)狀態(tài)機(jī)m2_state復(fù)位時(shí),即進(jìn)入m2_reset狀態(tài),并在 一個(gè)clk周期后進(jìn)入m2_hold_clk_l狀態(tài),當(dāng)ps2_clk_hi_z(時(shí)鐘線)被拉低并保持400μS后進(jìn)入m2_data_low_1狀態(tài),此時(shí)向鼠標(biāo) 發(fā)送起始 位和d[0]、d[1](d[0]=d[1]=0)。完成后進(jìn)入m2_data_high_1狀態(tài), 發(fā)送d[2](d[2]=1)并進(jìn)入m2_data_low_2狀態(tài),此時(shí)向鼠標(biāo)發(fā)送d[3]位(d[3]=0), 完成發(fā)送進(jìn)入m2_data_high_2狀態(tài),向鼠標(biāo)發(fā)送d[4]、d[5]、d[6]、d[7](d[4]=d[5]=d[6]=d[7]=1),完成發(fā)送進(jìn)入m2_data_low_3狀 態(tài),向鼠標(biāo)發(fā)送奇偶校驗(yàn)位,然后進(jìn)入m2_data_high_3狀態(tài),將數(shù)據(jù)線拉高,等待鼠標(biāo)返回應(yīng)答信號。若PS/2時(shí)鐘信號下降沿來臨時(shí),數(shù)據(jù)線仍未變?yōu)楦唠娖?,則進(jìn)入m2_error_no_ack狀態(tài),此時(shí)握手失敗,系統(tǒng)將保持m2_error_no_ack狀態(tài)直到下一次復(fù)位,否則進(jìn)入m2_await_response狀態(tài)接收應(yīng)答字,接收完成進(jìn)入m2_verify數(shù)據(jù)校驗(yàn),然后進(jìn)入m2_use狀態(tài),鎖存輸出數(shù)據(jù),并進(jìn)入m2_wait狀態(tài),等待接收數(shù)據(jù)。當(dāng)檢測到時(shí)鐘下降沿后進(jìn)入m2_gather狀態(tài),接收鼠標(biāo)數(shù)據(jù)包,接收完成進(jìn)入m2_verify狀態(tài),此時(shí)便形成了數(shù)據(jù)接收循環(huán)。


          PS/2程序源碼

          entity mouse is
          Port (clk : in std_logic; reset : in std_logic; ps2_clk : inout std_logic; ps2_data : inout std_logic; left_button : out std_logic; right_button : out std_logic; mousex: buffer std_logic_vector(9 downto 0); mousey: buffer std_logic_vector(9 downto 0); data_ready : out std_logic; error_no_ack : out std_logic);
          end mouse;
          architecture Behavioral of mouse is
          --變量、信號定義(略)
          begin
          ps2_clk = '0' when ps2_clk_hi_z='0' else 'Z';
          ps2_data = '0' when ps2_data_hi_z='0' else 'Z';
          --檢測ps2clk上升沿和下降沿(略)
          m2statech: process (reset, clk) ------------------m2 狀態(tài)
          begin
          if (reset='0') then
          m2_state = m2_reset;
          elsif (clk'event and clk='1') then
          m2_state = m2_next_state;
          end if;
          end procESS;
          --m2 狀態(tài)傳輸邏輯
          m2statetr: process (m2_state, q, fall,rise,watchdog_timer_done,bitcount,ps2_data,packet_good)
          begin
          ps2_clk_hi_z = '1';
          ps2_data_hi_z = '1';
          error_no_ack = '0';
          output_strobe = '0';
          case m2_state is
          when m2_reset => -- 復(fù)位后向鼠標(biāo)發(fā)送命令字
          m2_next_state = m2_hold_clk_l;
          when m2_wait =>
          if (fall='1') then
          m2_next_state = m2_gather;
          else
          m2_next_state = m2_wait;
          end if;
          when m2_gather =>
          if ((watchdog_timer_done='1') and (bitcount=TOTAL_BITS))then
          m2_next_state = m2_verify;
          else
          m2_next_state = m2_gather;
          end if;
          when m2_verify =>
          --if (bitcount TOTAL_BITS) then
          --m2_next_state = m2_wait;
          --else
          m2_next_state = m2_use;
          --end if;
          when m2_use =>
          output_strobe = '1';
          m2_next_state = m2_wait;
          -- 用狀態(tài)機(jī)的9個(gè)狀態(tài)實(shí)現(xiàn)命令字傳輸,使鼠標(biāo)進(jìn)入"streaming"模式,并等待鼠標(biāo)正確應(yīng)答



          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();