VHDL:(vcom-1136:std_logic_vector 未定义)

VHDL: (vcom-1136: std_logic_vector undefined)

出现一个看似无法解释的语法错误,指出 std_logic 未定义,即使它在代码的早期编译时也是如此!第一个错误发生在实体的开头,即第 37 行。我相信这与创建我自己的包有关,但这是我以前做过的事情,从未出现过这个错误!感谢您的帮助。

  library IEEE;
  use IEEE.std_logic_1164.all;
  use IEEE.std_logic_unsigned.all;

  package lab2 is  
  constant SWIDTH: integer := 4;
  subtype state_type is 
    std_logic_vector(SWIDTH-1 downto 0); 

  constant S1: state_type  := "0000"; --these are the "reset states"
  constant S2: state_type  := "0001";
  constant S3: state_type  := "0010";
  constant S4: state_type  := "0011";
  constant S5: state_type  := "0101";
  constant S6: state_type  := "0110";
  constant S7: state_type  := "0111"; -- these are the "show letter" states
  constant S8: state_type  := "1000";
  constant S9: state_type  := "1001";
  constant S10: state_type := "1010";
  constant S11: state_type := "1011";

  constant G : std_logic_vector(7 downto 0) := x"47";
  constant a : std_logic_vector(7 downto 0) := x"61";
  constant r : std_logic_vector(7 downto 0) := x"72";
  constant e : std_logic_vector(7 downto 0) := x"65";
  constant send1 : std_logic_vector(7 downto 0) := x"38";
  constant send2 : std_logic_vector(7 downto 0) := x"0C";
  constant send3 : std_logic_vector(7 downto 0) := x"01";
  constant send4 : std_logic_vector(7 downto 0) := x"06";
  constant send5 : std_logic_vector(7 downto 0) := x"80";

end package;

------------------------------------

entity lab2 is
    port(     key : in std_logic_vector(3 downto 0);  -- pushbutton switches
            sw : in std_logic_vector(8 downto 0);  -- slide switches
            ledg : out std_logic_vector(7 downto 0);
            lcd_rw : out std_logic;
            lcd_en : out std_logic;
            lcd_rs : out std_logic;
            lcd_on : out std_logic;
            lcd_blon : out std_logic;
            lcd_data : out std_logic_vector(7 downto 0);
            hex0 : out std_logic_vector(6 downto 0));  -- one of the 7-segment diplays
end lab2 ;

错误发生在端口中,其中显示 std_logic 和 std_logic_vector 是未知引用。

entity之前还需要使用IEEE.std_logic_1164.all,如:

library IEEE;
use IEEE.std_logic_1164.all;

entity lab2 is

第一个IEEE.std_logic_1164.all仅适用于同一包的packagepackage body,而不适用于任何其他设计对象,如entitypackage,即使这些恰好在同一个文件中。

这允许在同一个文件中创建不同的设计对象,同时仍然控制来自库和包的可见对象。