如何在 1 和 0 之间切换 std_logic

How to toggle a std_logic between 1 and 0

我想在每次输入 sel='1' 时切换 std_logic 向量“1”和“0”。 我用下面的方法试过了,但两行都出错了。

selected <= not selected when sel='1';

ERROR: This construct is only supported in VHDL 1076-2008

selected <= ~selected when sel='1';

ERROR: Syntax error near "~"

是否有更好的切换方式,或者 'not' 函数的正确语法是什么。

这里是整个架构的代码:

architecture Behavioral of selWeerg is

signal selected : std_logic;

begin   
process(sel,digl,sysclk)
begin
    if rising_edge(sysclk) then

        selected <= ~selected when sel='1';

        if selected = '0' then
            digO1<=digl(3 downto 0);
        else
            digO2<=digl(3 downto 0);
        end if;
    end if;
end process;
end Behavioral;

错误消息告诉您它不起作用:您编写的代码仅在 VHDL-2008 中受支持,在以前的版本中不受支持。在以前的版本中,在进程中使用 when-else 结构是非法的。为什么?谁知道?这可能就是它在 VHDL-2008 中合法化的原因。

因此,您要么需要在模拟器上启用 VHDL-2008 编译,要么改用 if 语句。使用 VHDL-2008 并不是一个可以轻易做出的决定,因为很多工具并不理解它。