miaocounter6.vhd

来自「基本计时(12进制」· VHDL 代码 · 共 52 行

VHD
52
字号
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_arith.all;
USE IEEE.std_logic_unsigned.all;
ENTITY miaocounter6 IS
	GENERIC(LEN: integer:=6);
	PORT(clkin: in std_logic;	
		 Rf: in std_logic;
		 Cout,miaoset2,miaoalarm2,miao2alarm2: out std_logic;
		 A: out std_logic_vector(3 downto 0));
END miaocounter6;

ARCHITECTURE behave of miaocounter6 IS
	signal s_cnt:integer range 0 to LEN -1;
	signal r_cnt:integer range 0 to LEN -1;
begin			
	process(clkin,Rf,s_cnt)
			variable cnt:integer range 0 to LEN-1;
			variable c:std_logic;
	begin
		if Rf='0' then
			cnt:=0;
		elsif rising_edge(clkin)then
			if cnt = LEN -1 then
				c:='1';
			else
				c:='0';
			end if;
			if cnt =LEN -1 then
				cnt:=0;
			else
				cnt:=cnt+1;
			end if;
		end if;
		if cnt = 0 then
			miaoset2 <='1';
			miaoalarm2 <='1';
			miao2alarm2 <='0';
		elsif cnt = 1 then
			miaoset2 <='0';
			miaoalarm2 <='0';
			miao2alarm2 <='1';
		else
			miaoset2 <='0';
			miaoalarm2 <='0';
			miao2alarm2 <='0';
		end if;
		s_cnt<=cnt;
		A<=conv_std_logic_vector(s_cnt,4);
		Cout<=c;
	end process;
end behave;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?