count_decount.vhd

来自「c est un compteur et decompteur en vhdl」· VHDL 代码 · 共 45 行

VHD
45
字号
library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_SIGNED.ALL;entity Count_Decount isgeneric(n:integer:=13);port (          clk   : in std_logic;	     reset  : in std_logic;	     CD     : out std_logic_vector(n-1 downto 0)      );end Count_Decount;architecture Behavioral of Count_Decount isconstant min : std_logic_vector(n-1 downto 0):="1000000000000";constant max : std_logic_vector(n-1 downto 0):="0111111111111";signal CD_int : std_logic_vector(n-1 downto 0);signal up : std_logic;beginprocess(clk,reset)beginif reset='1'    then CD_int<= (others=>'0');   elsif (clk'event and clk='1') 	   then    	      if (CD_int=max-1 )	         then up<='1';            elsif  (CD_int=min+1)		         then up<='0';      	      else up<=up;	      end if;	      if up='0'	         then CD_int<=CD_int+1;	         else CD_int<=CD_int-1;	      end if;      else CD_int<=CD_int;end if;CD<= CD_int;end process;end Behavioral;

⌨️ 快捷键说明

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