-- mod10counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mod10counter is --实体名与文件名一致
generic(
cnt_mod_value: integer:=10--定义模值
);port(
i_lamp_clk:in std_logic;--时钟频率 1Hz时钟
i_sys_res:in std_logic;--复位
o_lamp_val:out std_logic_vector(3 downto 0)--输出为4维向量
);
end entity mod10counter;
architecture behave of mod10counter is--定义实体行为
signal r_lamp_count:std_logic_vector(3 downto 0);--中间变量
begin
process(i_lamp_clk)
begin
if(i_lamp_clk'event and i_lamp_clk='1') then
if(i_sys_res='1') then--复位时从0000开始
r_lamp_count<="0000";
elsif (r_lamp_count="1001")then--到达最后一个状态 从0000开始重复
r_lamp_count<="0000";else
r_lamp_count<=unsigned(r_lamp_count)+'1';
end if;
end if;
end process;
o_lamp_val <= r_lamp_count;--结果传给out变量
end architecture behave;