新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 基于FPGA的PS/2鼠標接口設計方法及其應用

        基于FPGA的PS/2鼠標接口設計方法及其應用

        作者: 時間:2012-02-08 來源:網絡 收藏

        when m2_hold_clk_l =>
        ps2_clk_hi_z = '0'; -- 啟動看門狗!
        if (watchdog_timer_done='1') then
        m2_next_state = m2_data_low_1;
        else
        m2_next_state = m2_hold_clk_l;
        end if;
        when m2_data_low_1 =>
        ps2_data_hi_z = '0'; -- 數據位 開始位, d[0] and d[1]
        if (fall='1' and (bitcount = 2)) then
        m2_next_state = m2_data_high_1;
        else
        m2_next_state = m2_data_low_1;
        end if;
        when m2_data_high_1 =>
        ps2_data_hi_z = '1'; -- 數據位 d[2]
        if (fall='1' and (bitcount = 3)) then
        m2_next_state = m2_data_low_2;
        else
        m2_next_state = m2_data_high_1;
        end if;
        when m2_data_low_2 =>
        ps2_data_hi_z = '0'; -- 數據位 d[3]
        if (fall='1' and (bitcount = 4)) then
        m2_next_state = m2_data_high_2;
        else
        m2_next_state = m2_data_low_2;
        end if;
        when m2_data_high_2 =>
        ps2_data_hi_z = '1'; -- 數據位 d[4],d[5],d[6],d[7]
        if (fall='1' and (bitcount = 8)) then
        m2_next_state = m2_data_low_3;
        else
        m2_next_state = m2_data_high_2;
        end if;
        when m2_data_low_3 =>
        ps2_data_hi_z = '0'; -- 奇偶校驗位
        if (fall='1') then
        m2_next_state = m2_data_high_3;
        else
        m2_next_state = m2_data_low_3;
        end if;
        when m2_data_high_3 =>
        ps2_data_hi_z = '1'; -- 允許鼠標拉成低電平(ACK脈沖)
        if (fall='1' and (ps2_data='1')) then
        m2_next_state = m2_error_no_ack;
        elsif (fall='1' and (ps2_data='0')) then
        m2_next_state = m2_await_response;
        else
        m2_next_state = m2_data_high_3;
        end if;
        when m2_error_no_ack =>
        error_no_ack = '1';
        m2_next_state = m2_error_no_ack;

        -- 為了鼠標正確進入"streaming"模式,狀態極必須等待足夠長的時間,確保鼠標正確應答0xFA。

        when m2_await_response =>
        --if (bitcount = 22) then
        m2_next_state = m2_verify;
        --else
        -- m2_next_state = m2_await_response;
        --end if;
        when others => m2_next_state = m2_wait;
        end case;
        end process;-----------------------------m2 狀態結束
        -- 位計數器 (略)
        -- 數據移位寄存器(略)
        -- 看門狗時間計數器(略)
        watchdog_timer_done = '1' when (watchdog_timer_count=WATCHDOG-1) else '0';
        packet_good = '1'; -- 接收數據包有效標志
        outdata: process (reset, clk) -- 輸出數據
        begin
        if (reset='0') then
        left_button = '0';
        right_button = '0';
        elsif (clk'event and clk='1') then
        if (output_strobe='1') then
        left_button = q(1);
        right_button = q(2);
        mouseyy = not (q(6) q(6) q(30 downto 23)) + "1";
        end if;
        end if;
        end process;
        cordinatex: process (reset, clk)
        begin
        if (reset='0') then
        mousex = "0110010000"; -- 400
        elsif (clk'event and clk='1') then
        if (output_strobe='1') then
        if ((mousex >= 797 and q(5)='0') or (mousex = 2 and
        q(5)='1')) then
        mousex = mousex;
        else
        mousex = mousex + (q(5) q(5) q(19 downto
        12));--q(5):xsign q(6):ysign
        end if;
        end if;
        end if;
        end process;
        cordinatey: process (reset, clk)
        begin
        if (reset='0') then
        mousey = "0100101100"; -- 300
        elsif (clk'event and clk='1') then
        if (output_strobe='1') then
        if ((mousey >= 597 and q(6)='1') or (mousey = 2
        and q(6)='0')) then
        mousey = mousey;
        else
        m ousey = mousey + mouseyy; --(q(6) q(6) q(30
        downto 23));
        end if;
        end if;
        end if;
        end process;
        data_ready = output_strobe;
        end Behavioral;


        結束語

          該設計采用了清華大學THCII-1創新SoPC實驗套件進行綜合、仿真和下載,測試得到了滿意的效果,完整地實現了對PS/2和VGA的時序驅動。

          該設計可以被應用到各種需要鼠標操作、以VGA作為顯示的中,從而大大提高人機交互能力,降低了開發成本,提高了開發效率,使系統的穩定性也得到了可靠的保障。


        上一頁 1 2 3 4 下一頁

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 永康市| 图木舒克市| 保亭| 双桥区| 沙坪坝区| 黄龙县| 庐江县| 涪陵区| 乌兰浩特市| 津市市| 久治县| 宜阳县| 芦山县| 绿春县| 饶阳县| 古田县| 汕尾市| 定陶县| 巫山县| 兴国县| 厦门市| 浦江县| 津南区| 名山县| 开化县| 宣武区| 南部县| 靖宇县| 汉中市| 嫩江县| 扶绥县| 镇宁| 樟树市| 八宿县| 繁峙县| 柘荣县| 宜黄县| 新干县| 东安县| 钟山县| 南澳县|