2013-03-09 66 views
5

我有以下代碼(它編碼的號碼的按下的按鈕的):VHDL:與選多個值

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; 

回答

3

,而不是與選擇,你可以使用情況:

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; 
+1

它只能在流程:http://www.quicknet.se/hdc/hdl/ educaton/mux4_1/index.htm – rburny 2013-03-20 00:12:31

+0

有沒有特別的原因讓你不想把它放在一個過程中? – TOTA 2013-03-20 16:06:46

+1

我只是在學習VHDL,我正在尋找最簡單,最優雅的解決方案。如果我將組合代碼放在一個過程中,是否有任何語義差異? – rburny 2013-03-21 17:29:51