LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
----------------------------------------
ENTITY zuoye IS
PORT( cp,reset : in std_logic;
Data,cc : in std_logic_vector(3 downto 0);
q : buffer std_logic;
count : buffer integer range 7 downto 0;
Din : in std_logic_vector(7 downto 0);
Dout : out std_logic_vector(7 downto 0));
end;
-------------------------------------------
architecture aa of zuoye is
signal load,en : std_logic;
signal qq : std_logic_vector(3 downto 0);
signal R,REG : std_logic_vector(7 downto 0);
TYPE states IS (st0, st1, st2, st3);
signal STA : states := st0;
BEGIN
process(STA,cp,reset)
begin
-- if reset='1' then STA<=st0;
if cp'event and cp='1' then
CASE STA IS
WHEN st0 => en <= '1'; STA <= st1;
WHEN st1 => if count=7 then en<='0'; STA<=st2; end if;
WHEN st2 => REG <= R xor Din; STA<=st3;
WHEN others =>Dout <= REG xor Din;STA<=st0;
end CASE;
end if;
END process;
process(cp,en)
begin
if en='1' then qq<=data;
elsif cp'event and cp='1' then
qq<=((qq(0) and cc(0)) xor (qq(1) and cc(1)) xor (qq(2) and cc(2)) xor (qq(3) and cc(3)))&qq(3 downto 1);
count<=count+1;
end if;
R(count)<=qq(0);
END process;
end aa;
这个程序编译时候已经没有问题了 但是时序仿真count只计数一个 还有我是想在 WHEN st1 => 时候count计数满了就shi en为零 这样第二个process就不工作了 高手帮帮忙啊 仿真图如下 我不会上传仿真图 反正就是count只计数一次
process(cp,en)
begin
if en='1' then
qq <=data;
elsif cp'event and cp='1' then
qq <=((qq(0) and cc(0)) xor (qq(1) and cc(1)) xor (qq(2) and cc(2)) xor (qq(3) and cc(3)))&qq(3 downto 1);
count <=count+1;
end if;
R(count) <=qq(0);
END process;
你这个进程的逻辑是en为'1'时,qq载入数据;en为'0'时,时钟驱动计数器计数。这和你描述的逻辑不一样啊。按照你说的逻辑代码应该是:
process(cp,en)
begin
if en='1' then
if cp'event and cp='1' then
qq <=((qq(0) and cc(0)) xor (qq(1) and cc(1)) xor (qq(2) and cc(2)) xor (qq(3) and cc(3)))&qq(3 downto 1);
count <=count+1;
end if;
else
qq <=data;
end if;
R(count) <=qq(0);
END process;