我有以下代码(它编码了一些按下的按钮):
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;
答案 0 :(得分:3)
您可以使用大小写代替select:
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 :(得分:0)
或者您可以将其写为2个单独的/ 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是一种编译语言 - 或者是合成的。只要综合工具创建相关的逻辑构造,任何格式都可以。其余的是允许理解和维护代码的语法。