0
entity address_decoder is
PORT(address : in STD_LOGIC_VECTOR ( 0 to 3 );
  decoded_address : out integer range 0 to 15);
end address_decoder;

architecture dataflow of address_decoder is
begin
PROCESS(address)
begin
    if address = "0000" then decoded_address <= '0';
    elsif address = "0001" then decoded_address <= '1';
    elsif address = "0010" then decoded_address <= '2';
    elsif address = "0011" then decoded_address <= '3';
    elsif address = "0100" then decoded_address <= '4';

这是即将到来的错误

错误:HDLParsers:800 decoded_address 类型与“0”类型不兼容。错误:HDLParsers:800 decoded_address 类型与“1”类型不兼容。错误:HDLParsers:800 decoded_address 类型与“2”类型不兼容。错误:HDLParsers:800 decoded_address 类型与“3”类型不兼容。错误:HDLParsers:800 decoded_address 类型与“4”类型不兼容。

是不是因为address和decoded_address是两种不同的数据类型?关于如何摆脱这个错误的任何想法?

4

2 回答 2

1

提供此答案是因为ERROR:HDLParsers:800Stackoverflow 上的其他 7 次出现不涉及分配给整数类型的文字,并且 Morten 认为该问题的实际答案可能很有价值。与答案最接近的匹配问题(参见VHDL:“变量”类型与 <= 类型不兼容)涉及具有位字符串文字值的整数赋值目标)。

在此 if 语句中(缺少并结束 if):

if address = "0000" then decoded_address <= '0';
elsif address = "0001" then decoded_address <= '1';
elsif address = "0010" then decoded_address <= '2';
elsif address = "0011" then decoded_address <= '3';
elsif address = "0100" then decoded_address <= '4';

显示的 if 语句部分应如下所示:

if address = "0000" then decoded_address <= 0;
elsif address = "0001" then decoded_address <= 1;
elsif address = "0010" then decoded_address <= 2;
elsif address = "0011" then decoded_address <= 3;
elsif address = "0100" then decoded_address <= 4;

decode_address 被声明为范围为 0 到 15 的受限整数与字符文字“0”、“1”、“2”、“3”和“4”之间存在类型不匹配。

更正后的 if 语句端口将数字文字(与整数类型兼容)分配给 decoded_address。请注意,所有五个值都在 decode_address 的范围约束内。

于 2014-12-31T11:36:02.970 回答
0

除了@David Koontz 的回答,您还可以使用 case 语句。

case address is when "0000" => decoded_address <= 0; when "0001" => decoded_address <= 1; when "0010" => decoded_address <= 2; when "0011" => decoded_address <= 3; when others => decoded_address <= 4; end case;

并且永远不会忘记涵盖所有条件。


顺便说一句,我不知道这是否是课堂作业,但你可以使用

decoded_address <= to_integer(unsigned(address));

当然你需要添加 use ieee.numeric_std.all

于 2014-12-31T12:08:03.907 回答