ls161的11脚(q3)和13脚(q1)接到ls20的其中一个与非门的两个输入端,ls20是双4输入与非门,也就是一个与非门有四个输入端,所以另外两个输入端应该接高电平,然后把这个与非门的输出端接到ls161的cr非端(1脚)。输出就是一个十进制计数器了,计到10会自动清零。
这就是一个32位加法计数器,有清零、复位和使能输入
entity auto_counter is
port (
clk : in std_logic;
rst_n : in std_logic;
clr : in std_logic;
en : in std_logic;
counter : std_logic_vector(31 downto 0) < type > );
end auto_counter;
architecture behave of auto_counter is
begin -- behave
process (clk, rst_n)
begin -- process
if rst_n = '0' then -- asynchronous reset (active low)
counter <= (others => '0');
elsif clk'event and clk = '1' then -- rising clock edge
if clr = '0' then
if en = '1' then
counter <= counter + 1;
else
counter <= counter;
end if;
else
counter <= (others => '0');
end if;
end if;
end process;
end behave;