如何在VHDL中测试4x4键盘

时间:2018-09-27 11:20:49

标签: vhdl keypad

我正在尝试在vhdl中提出一个简单的4x4键盘FSM。我已经在Google上搜索了,并且找不到真正的示例,也找不到我所拥有的东西,我想不出一种用测试台进行测试的方法。我在Spartan-3E上使用ISE。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

entity keypad is
port(
    clk, reset: in std_logic;
    kcol: in std_logic_vector(3 downto 0);
    krow: out std_logic_vector(3 downto 0);
    key_press: out std_logic_vector(7 downto 0);
    valid: out std_logic
    );
end keypad;

architecture arch of keypad is

    type kstate_type is (idle1, start, wait1, done);
    signal kstate_reg, kstate_next: kstate_type;

    signal scan: std_logic_vector(3 downto 0);
    signal res_col: std_logic_vector(3 downto 0);

begin

key_pressed_proc: process(clk,reset, kstate_reg, kcol)
begin
    if reset = '0' then
        krow <= (others=>'1');
        scan <= "1110";
        kstate_reg <= idle1;
        kstate_next <= idle1;
        res_col <= (others=>'1');
        valid <= '0';

    elsif clk'event and clk = '1' then
        case kstate_reg is
            when idle1 =>
                valid <= '0';
                if kcol /= "1111" then
                kstate_next <= start;
                end if; 
            when start =>
                case scan is
                    when "1110" => scan <= "1101";
                    kstate_next <= wait1;
                    when "1101" => scan <= "1011";
                    kstate_next <= wait1;
                    when "1011" => scan <= "0111";
                    kstate_next <= wait1;
                    when "0111" => 
                    scan <= "1110";
                    krow <= (others=>'1');
                    kstate_next <= done;
                    key_press <= scan & res_col;
                    when others =>
                end case;
            when wait1 =>
                krow <= scan;
                if kcol(0) = '0' then
                res_col <= "0111";
                end if;
                if kcol(1) = '0' then
                res_col <= "1011";
                end if;
                if kcol(2) = '0' then
                res_col <= "1101";
                end if;
                if kcol(3) = '0' then
                res_col <= "1110";
                end if;
                kstate_next <= start;
            when done =>
                if kcol = "1111" then
                    valid <= '0';
                    key_press <= (others=>'0');
                    kstate_next <= idle1;
                end if; 
        end case;
        kstate_reg <= kstate_next;
    end if;
end process;

end arch;

冒着听起来像是一个学生试图让某人去做我的功课的风险,有人可以告诉我这是否可行,然后再连接电线并尝试用Xilinx芯片上的4个LED对其进行调试使用吗?

0 个答案:

没有答案