*1 含异步复位和时钟使能的D触发器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DFF1 IS
PORT(CLK,RST,EN,D: IN STD_LOGIC;
Q: OUT STD_LOGIC);
END DFF1;
ARCHITECTURE bhv OF DFF1 IS
SIGNAL Q1:STD_LOGIC;
BEGIN
PROCESS(CLK,Q1,RST,EN)
BEGIN
IF RST='1' THEN Q1<='0';ELSIF CLK'EVENT AND CLK='1' THEN
IF EN='1' THEN Q1<=D;END IF;
END IF;
END PROCESS;
Q<=Q1;
END bhv;
*2含同步复位的D触发器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DFF2 IS
PORT(CLK,RST, D: IN STD_LOGIC;
Q: OUT STD_LOGIC);
END DFF2;
ARCHITECTURE bhv OF DFF2 IS
SIGNAL Q1:STD_LOGIC;
BEGIN
PROCESS(CLK,Q1,RST,)
BEGIN
IF CLK'EVENT AND CLK='1' THEN
IF RST=’1’THEN Q1<=’0’;ELSE Q1<=D; END IF
END IF;
END PROCESS;
Q<=Q1;
END bhv;
*3 给出含有异步清0和计数使能的16位二进制加减可控计数器的VHDL描述。
LIBRARY IEEE;
USE IEEE STD_LOGIC_1164 ALL;
USE IEEE STD_LOGIC_UNSIGNED ALL;
ENTITY ADD_SUB_LOAD_16 IS
PORT(CKC,RST,ADD_EN,SUB_EN,LOAD:IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(15 DOWNTO 0);
CQ:IN STD_LOGIC_VECTOR(15 DOWNTO 0);
COUT :OUT STD_LOGIC);
END ENTITY ADD_SUB_LOAD_16;
ARCHITECTURE A_S_16 OF ADD_SUB_LOAD_16 IS
BEGIN
PROCESS(CKC,RST,ADD_EN,SUB_EN,LOAD)
VARIABLE CQI:STD_LOGIC_VECTOR(15 DOWNTO0);
BEGIN
IF RST= ‘1’ THEN CQL:=(OTHERS=>’0’);
ELSIF LOAD=’1’ THEN CQL:=DATA;
ELSIF CLK’EVENT AND CLK=’1’ THEN
IF ADD_EN=’1’
IF CQI<#FFFFF# THEN CQL=CQI+1;
ELSE CQL:=(OTHERS=>’0’);
END IF;
IF CQI=16#FFFF# THEN COUT<’1’;
ELSE COUT<=’0’;
END IF;
IF SUB_EN=’1’THEN
IF CQI>’0’THEN CQI:=CQI-1;
ELSE CQI:=(OTHERS=>’1’);
END IF;
IF CQI=’0’THEN COUT<=’1’;
ELSE COUT<=’0’;
END IF;
END IF;
ENDIF;
CQ<=CQI;
END PROGRESS;
ENDARCHITECTURE A_S_16;