6

我有以下代码(它编码了许多按下的按钮):

with buttons select
  tmp <= "000" when x"1",
         "001" when x"2",
         "010" when x"4",  
         "011" when x"8",
         "100" when others;
code <= input(1 downto 0);
error <= input(2);

我试图在不使用tmp信号的情况下重写它。可能吗?以下不起作用:

with buttons select
  error & code <= "000" when x"1",
                  "001" when x"2",
                  "010" when x"4",  
                  "011" when x"8",
                  "100" when others;
4

2 回答 2

5

您可以使用案例而不是选择:

my_process_name : process(buttons)
begin
  case buttons is
    when x"1" =>
      error <= '0';
      code  <= "00";
    when x"2" =>
      error <= '0';
      code  <= "01";
    when x"4" =>
      error <= '0';
      code  <= "10";
    when x"8" =>
      error <= '0';
      code  <= "11";
    when others =>
      error <= '1';
      code  <= "00";
  end case;
end process;
于 2013-03-09T20:08:57.283 回答
0

或者您可以将其写为 2 个单独的 with/when 语句:

with buttons select
  error <= '0' when x"1",
           '0' when x"2",
           '0' when x"4",  
           '0' when x"8",
           '1' when others;
with buttons select
  code <= "00" when x"1",
          "01" when x"2",
          "10" when x"4",  
          "11" when x"8",
          "00" when others;

或者:

error <= '0' when (buttons = X"1" or buttons = X"2" buttons = X"4" buttons = X"8") else '1'; 
code <= "00" when buttons = X"1" else "01" when buttons = X"2" else "10" when buttons = X"4" else "11" when buttons = X"8" else "00"; 

VHDL 是一种编译语言 - 或综合语言。只要综合工具创建相关的逻辑结构,任何格式都可以。剩下的就是允许代码被理解和维护的语义。

于 2018-05-15T16:30:20.120 回答