16
进制加法计数器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_unsigned.ALL;
-----------------------------------
ENTITY counter16 IS
PORT(
clk,clr,enb: IN
STD_LOGIC;
cout:OUT STD_LOGIC;
q: OUT STD_LOGIC_vector(3 downto 0));
END counter16;
---------------------------------
ARCHITECTURE one OF counter16 IS
Signal Q1: STD_LOGIC_vector(3 downto 0);
BEGIN
process(clk,clr,enb,Q1)
begin
if clr='0' then Q1<="0000";
elsif clk'event and clk='1' then
if enb='1' then
if Q1<15 then
Q1<=Q1+1;
else Q1<=(others=>'0');
end if;
end if;
end if;
if Q1>14 then cout<='1';
else cout<='0';
end if;
end process;
Q<=Q1;
END one;
--------------------------------