VHDL键盘代码问题

时间:2014-07-18 10:13:41

标签: vhdl keypad

我有一个4x3键盘,我写这个FSM用于连接我的Nexys2板,我遇到的麻烦是

  1. 当我运行代码时,LED会在没有按任何键的情况下发光,它会自动显示随机组合

  2. 当我按下一个键时,它会显示特定的组合,然后在没有按任何键的情况下进入ROW的下一个条件。有时,如果按一个键,它甚至不会响应。

  3. 发生了什么事?这段代码有什么问题?我很无能为力。有人可以指出错误并提出一些解决方案吗?这是我的代码

    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.NUMERIC_STD.ALL;
    
    
    entity keypad_3x4 is
         Port ( CLK     : in  STD_LOGIC;
                  RESET     : in  STD_LOGIC;
                  ROW   : in  STD_LOGIC_VECTOR (3 downto 0);
                  COL   : out STD_LOGIC_VECTOR (2 downto 0);
                  LED       : out STD_LOGIC_VECTOR (3 downto 0)
                  );
    end keypad_3x4;
    
    
    architecture Behavioral of keypad_3x4 is
    architecture Behavioral of keypad_3x4 is
    
    
     TYPE STATE_TYPE is
        (   RESET_ST,
            S1,
            S2,
            S3,
            S4,
            S5,
            S6
        );
    
    signal  state:  STATE_TYPE;
    begin
    
     process (CLK, RESET)
     begin
    
        if  (RESET = '1') then
            state       <= RESET_ST;    
        elsif   (CLK'event and CLK = '1') then
    
        case (state) is 
    
        WHEN RESET_ST       =>
                LED             <= (others => '0');
                COL         <= (others => '0');
                state           <= S1;
    
        WHEN S1         =>
            COL             <= "001";       --C1 selected
            LED             <= (others => '0');
            state           <= S2;
    
        WHEN S2         =>
            if  ROW         <= "0001" then
                    led         <= "0001";  --1     
            elsif ROW       <= "0010" then
                    led         <= "0100";  --4     
            elsif ROW       <= "0100" then
                    led         <= "0111";  --7     
            elsif ROW       <= "1000" then
                    led         <= "1111";  --*     
            else
                    LED         <= (others => '0');
                    state       <= S3;
            end if;
    
        WHEN S3         =>
            COL             <= "010";       --C2 selected
            LED         <= (others => '0');
            state           <= S4;
    
        WHEN S4     =>
            if  ROW <= "0001" then
                    led <= "0010";  --2 
            elsif ROW <= "0010" then
                    led <= "0101";  --5     
            elsif ROW <= "0100" then
                    led <= "1000";  --8
            elsif ROW <= "1000" then
                    led <= "0000";  --0
            else
                    LED         <= (others => '0');
                    state       <= S5;
            end if;
    
        WHEN S5     =>
            COL             <= "100";       --C3 selected
            LED             <= (others => '0');
            state           <= S6;
    
        WHEN S6     =>
            if  ROW <= "0001" then
                    led <= "0011";  --3
            elsif ROW <= "0010" then
                    led <= "0110";  --6
            elsif ROW <= "0100" then
                    led <= "1001"; --9
            elsif ROW <= "1000" then
                    led <= "1111";  --#
            else
                    LED         <= (others => '0');
                    state       <= RESET_ST;
            end if;
    
        WHEN others =>
                    state       <= RESET_ST;    
        END case;
    END if;
    END process;
    
    end Behavioral;
    

0 个答案:

没有答案