library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity counter is
port(
allow,reset,clk :in bit;
o:out integer range 0 to 10;
c:out bit);
end counter;
architecture behaver of counter is
begin
p1: process (clk,reset,allow)
variable ot:integer range 0 to 10:=0;
variable t:bit ;
begin
if(reset='1')then o<=0;
elsif (allow='1') then
if(clk'event and clk='1')then
ot:=ot+1;t:='0';
if(ot>9) then ot:=0;t:='1';
end if;
end if;
o<=ot;
c<=t;
end if;
end process p1;
end architecture behaver;
我这个是十进制计数器,具体需要的话可以改一下输出形式。