2,425
社区成员
发帖
与我相关
我的任务
分享
library ieee;--4bit counter
use ieee.std_logic_1164.all;
use ieee.[size=14px]std_logic_unsigned
.all;--[color=#FF0000]这个库在哪可以找到?我用的是quartusII,在libraries下没找到[/color]
entity counter is
port(enable,clear,id,clk : in std_logic;--定义id表示加法器还是减法器
q: out std_logic_vector(3 downto 0) );
end entity counter;
architecture behav of counter is
begin
process(enable,clear,id,clk)
variable q1 : std_logic_vector(3 downto 0);
begin
if id='1' then --adder
if clear='1' then
q1 := "0000";
elsif clk'event and (clk='1') and (clk'last_value='0') then
if enable='1' then
q1 := q1 + 1;
end if;
end if;
end if;
if id='0' then --subtractor
if clear='1' then
q1 := "1111";
elsif clk'event and clk='1' then
if enable='1' then
q1 :=q1-1;
end if;
end if;
end if;
q <= q1;
end process;
end architecture behav;