我有以下代码(它对按下的按钮的编号进行编码):
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
signal的情况下重写它。有可能吗?以下代码不起作用:
with buttons select
error & code <= "000" when x"1",
"001" when x"2",
"010" when x"4",
"011" when x"8",
"100" when others;
发布于 2013-03-10 04:08:57
您可以使用case来代替with 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;
发布于 2018-05-16 00:30:20
或者,您可以将其编写为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是一种编译语言或综合语言。只要合成工具创建了相关的逻辑构造,任何格式都可以。其余的是系统学,允许代码被理解和维护。
https://stackoverflow.com/questions/15314463
复制相似问题