Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is 实体计数器是
port( clk : in std_logic;
enable : in std_logic;
clr : in std_logic;
gd : out std_logic;
q : buffer std_logic_vector(3 downto 0));
end counter;
architecture counter_arch of counter is
begin
( 进程标号)process(敏感信号表)(clk,enable,clr)
begin
if( clr='1')then
q<=(others=>'0'); 一次性按位赋值,全部位为零
elsif(clk'event and clk='1')then
if( enable='1')then
if(q(3)='1'and q(0)='1')then
q<=(others=>'0');
else
q<=q+1;
end if;
end if;
end if;
end process;
gd<=q(3) and q(0) and enable;