maxplus 和vhdl问题,急需~

来源:百度知道 编辑:UC知道 时间:2024/05/23 12:31:42
大家帮我看看这段代码,好像不能编译通过的,马凡帮我修改一下吧,谢谢了,代码不长的,急需!!!

LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
entity taxi is
port (d :in std_logic_vector(7 downto 0);
a :out std_logic_vector(2 downto 0));
end taxi;
architecture behav of taxi is
begin
if (d(7)='0') then
a<="111";
elsif(d(6)='0') then
a<="110";
elsif(d(5)='0') then
a<="101";
elsif(d(4)='0') then
a<="100";
elsif(d(3)='0') then
a<="011";
elsif(d(2)='0') then
a<="010";
elsif(d(1)='0') then
a<="001";
elsif(d(0)='0') then
a<="000";
end if;
end behav;
我是用vhdl语言在maxplus II软件里面编写的,但是complier 阶段就有错误,麻烦大家了,谢谢~

if语句必须放在过程process里面,所以在architecture中加入一个process,(d)表示敏感信号为d,即d变化时激活此process,把if语句放在process的begin和end之间就OK了。代码如下:

LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
entity taxi is
port (d :in std_logic_vector(7 downto 0);
a :out std_logic_vector(2 downto 0));
end taxi;
architecture behav of taxi is
begin
process(d)
begin
if (d(7)='0') then a<="111";
elsif(d(6)='0') then a<="110";
elsif(d(5)='0') then a<="101";
elsif(d(4)='0') then a<="100";
elsif(d(3)='0') then a<="011";
elsif(d(2)='0') then a<="010";
elsif(d(1)='0') then a<="001";
elsif(d(0)='0') then a<="000";
end if;
end process;
end behav;

if then只能用于顺序语句中,if generate加for generate用于并发语句可以嵌套使用,或者用Process

正如楼上所说;不过建议你用CASE语句来做 ^_^

<