library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity cnt10 is port ( clk,rst,en:in std_logic; cq:out std_logic_vector(3 downto 0); cout:out std_logic); end cnt10; architecture behav of cnt10 is begin process(clk,rst,en) variable cqi:std_logic_vector(3 downto 0); begin if rst='1' then cqi:=(others=>'0');--异步复位功能,rst放前边为异步,clk放前边为同步复位 elsif clk'event and clk='1' then --clk始终,产生上升沿 if en='1' then if cqi<"1010"then cqi:=cqi+1;--小于10加一计数 else cqi:=(others=>'0'); end if; end if; end if; if cqi="1001"then cout<='1';--进位程序 else cout<='0'; end if; end process; end behav;
本文作者为一木,转载请注明。