Nghiên cứu Khoa học
Thiết kế thanh ghi dịch phải 4 bit và Testbench
Chương trình Thiết kế Thanh ghi bit co chức năng dịch phải:
entity ShiftReg4bit_beh is
Port ( Din,clk,reset : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (3 downto 0));
end ShiftReg4bit_beh;
architecture Behavioral of ShiftReg4bit_beh is
signal Q_temp: std_logic_vector(3 downto 0);
begin
Process(clk,reset)
begin
if(reset='1')then
Q_temp<="0000";
elsif(clk'event and clk='1')then
Q_temp<= Din & Q_temp(3 downto 1);
end if;
end process;
Q <= Q_temp;
end Behavioral;
Chương trình Testbenchcho thanh ghi:
ENTITY test_ShiftReg4bits IS
END test_ShiftReg4bits;
ARCHITECTURE behavior OF test_ShiftReg4bits IS
COMPONENT ShiftReg4bit_beh
PORT(din,clk,reset : IN std_logic;
Q : OUT std_logic_vector(3 downto 0));
END COMPONENT;
signal din : std_logic := '0';
signal clk : std_logic := '0';
signal reset : std_logic := '0';
signal Q : std_logic_vector(3 downto 0);
BEGIN
uut: ShiftReg4bit_beh PORT MAP (din,clk,reset,Q);
clk_process :process
begin
clk <= '0'; wait for 100ns;
clk <= '1'; wait for 100ns;
end process;
stim_proc: process
begin
Reset <= '1';
Din<='1';
wait for 200ns;
Reset <= '0';
wait;
end process;
END;