我在一个学校项目工作,我不得不设计出售门票的机器。有很多要求,我照顾了很多人,但我有一个小问题。我,设计师决定机器中的票数是多少。然后,客户一次购买一张票后,这个数字应该减少一个单位。它不是。哪里不对? (当谈到以VHDL编写代码时,我是一名初学者)。这个vhdl代码并没有做我想做的事。我做错了什么?
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity bilete is
port(en1,en2: in std_logic;
init: in std_logic;
B: out std_logic_vector(15 downto 0);
err: out std_logic;
ok: out std_logic);
end bilete;
architecture Bil of bilete is
signal en : std_logic;
constant C: std_logic_vector(15 downto 0):=x"0002";
signal M: std_logic_vector(15 downto 0);
begin
en<= en1 nor en2;
P: process(en,init,M)
variable Verr: std_logic:='0';
variable Vok: std_logic:='0';
variable K: std_logic_vector(15 downto 0):=x"0000";
begin
if init='0' then -- inititialize the number of tickets
K:=C;
M<=K;
if en='0' then
Verr:='0';
B<=K;
Vok:='0';
else if K<0 then
Vok:='0';
B<=x"0000";
Verr:='1';
else if K>0 then
Verr:='0';
Vok:='1';
B<=K-x"0001";
K:=K-x"0001";
M<=K;
end if;
end if;
end if;
else if init='1' then -- decrement
if en='0' then
Verr:='0';
B<=M;
Vok:='0';
else if M<0 then
Vok:='0';
B<=x"0000";
M<=x"0000";
Verr:='1';
else if M>0 then
Verr:='0';
Vok:='1';
B<=M-x"0001";
M<=M-x"0001";
end if;
end if;
end if;
end if;
end if;
err<=Verr;
ok<=Vok;
end process P;
end Bil;
如果我没有错,条件语法应该是'elsif'而不是'else if'?为什么你有这么多'结束如果'? – annena
它可以是两个。如果对每个if语句都结束,我会结束。主要的问题是,我不知道如何在门票一个一个地出售之后更新门票的数量(以某个值初始化)。 –
首先:请格式化并缩进您的代码,请使用正确的缩进或elsif语句。其次,你的设计没有时钟。使用简短标识符名称确实会使设计更快或更小,这只会阻碍我们理解您的代码......我的最后一个注意事项:不要对std_logic_vector进行算术计算,使用signed或unsigned类型。 – Paebbels