首页 > 解决方案 > STD_LOGIC_VECTOR 与整数文字不匹配

问题描述

我对 VHDL 非常陌生,我正在尝试编写此代码,该过程根据输入 SW 驱动输出向量 HEX0。这就是我到目前为止所拥有的。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity top is
    port (SW : in std_logic_vector (3 downto 0);
        LEDR : out std_logic_vector (3 downto 0);
        HEX0 : out std_logic_vector (6 downto 0));
end entity;

architecture top_arch of top is
    begin
        LEDR <= SW;
            -- Decoder process goes here…
            process (SW)
                begin
                    if  (SW = "0000") then
                        HEX0 <= (100000);
                    elsif   (SW = "0001") then
                        HEX0 <= (100111);
                    end if;
        end process;
end architecture;

这是错误信息

10517 HVDL type mismatch error at top.vhd(17): std_logic_vector type does not match integer literal

我对此很陌生,所以我不知道为什么会这样。请让我知道你的想法。谢谢你。

标签: compiler-errorsvhdl

解决方案


在这些行中HEX0 <= (100000);HEX0 <= (100111);数字被解释为整数 100000 和 100111,而不是按位排列的 1 和 0。

它抱怨您试图将整数分配给std_logic_vector类型信号 - 这是不允许的。

要使用std_logic_vector文字,你会写:HEX0 <= "100000";HEX0 <= "100111";


推荐阅读