哪位帮忙个VHDL程序

2019-03-25 10:40发布

library IEEE ;
use IEEE.std_logic_1164.all ;
use IEEE.std_logic_unsigned.all ;
use IEEE.numeric_std.all ;

entity key1 is
port ( Clk_I   : in std_logic ;
        Rst_I   : in std_logic ;
        key_I : in std_logic ;
        key_O : out std_logic );
end entity ;
architecture rt1 of key1 is
   type state_type is (s0, s1, s2, s3, s4, s5);
   signal state     : state_type ;
   signal count     : integer range 0 to 80000 ;
   signal reg       : std_logic ;
   signal key_confirm : std_logic ;
begin
    reg <= key_I ;
  process (Clk_I, Rst_I)
    begin   
     if Rst_I = '0' then
              state <= s0 ;
      elsif Clk_I'event and Clk_I = '1' then
         
          case state is
               when s0 => if reg = '1' then
                               state <= s0;
                          else state <= s1;
                          end if ;
               when s1 => if count = 80000 then
                             count <= 0 ;
                             state <= s2 ;
                          else count <= count + 1 ;
                               state <= s1 ;
                          end if ;
               when s2 => if reg = '1' then
                               state <= s0 ;
                          else state <= s3;
                          end if ;
               when s3 => if reg = '1' then
                               state <= s0 ;
                          else state <= s4 ;
                          end if ;
               when s4 => if reg = '1' then
                               state <= s0 ;
                          else state <= s5 ;
                          end if ;
               when s5 => if reg ='0' then
                               state <= s0 ;
                          else state <= s5 ;
                          end if ;
               when others => state <= s0 ;
           end case ;
       end if ;
   end process ;
   process (Clk_I)
     begin
       if Clk_I'event and Clk_I = '1' then
         case state is
             when s5 => key_confirm <= '1' ;
             when others => key_confirm <= '0' ;
         end case ;
        end if ;
     end process ;
   key_O <= key_confirm ;
end rt1;
帮忙看看哪里有问题,谢谢! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
仙猫
2019-03-25 10:51
< /  有一处容易忽略的毛病,即“reg <= key_I;”必须用时钟锁存一下。
 另外(可能不重要):在复位或s0状态处给 count 赋个初值。

一周热门 更多>