Professional Documents
Culture Documents
Prelab:
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
entity huy is
port(
x,y,z: in std_logic;
c,s: out std_logic
);
end entity;
Mô phỏng :
2.2 Thiết kế bộ dồn kênh 4-1 (Mux 4-1)
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
entity huy2 is
port(
d0, d1, d2, d3: in std_logic;
s: in std_logic_vector(1 downto 0);
y: out std_logic
);
end entity;
Mô phỏng
2.3 Thiết kế bộ giải mã 2-4 (Decoder 2-4)
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
entity bai3 is
port(
x: in std_logic_vector(1 downto 0);
c: in std_logic;
y: out std_logic_vector(3 downto 0)
);
end entity;
begin
c_x <= c&x;
with c_x select
y <= "0001" when "100" ,
"0010" when "101" ,
"0100" when "110" ,
"1000" when "111" ,
"0000" when others;
end architecture;
Mô phỏng
I.Thí nghiệm 2.1 - Thiết kế bộ cộng 2 số 4 bit (Full Adder)
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
entity bai4 is
port(
a,b: in std_logic_vector(3 downto 0);
Cin: in std_logic;
s: out std_logic_vector(3 downto 0);
Cout:out std_logic
);
end entity;
Wave form
II. Thí nghiệm 2.2 – Thiết kế bộ ALU 4-bit
Code VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
use IEEE.numeric_STD.ALL;
entity alu is
port(
A, B : in std_logic_vector(3 downto 0);
sel : in std_logic_vector(2 downto 0);
Cin:in std_logic;
COut : out std_logic;
ketqua : out std_logic_vector(3 downto 0)
);
end entity alu;
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity bodemmaBCD is
port(
enable, load, up, reset, clk: in std_logic;
d: in std_logic_vector(3 downto 0);
co: out std_logic;
q: out std_logic_vector(3 downto 0)
);
end entity;
architecture behavioral of bodemmaBCD is
signal count: std_logic_vector(3 downto 0);
begin
process(reset, up, load, enable, clk, d)
begin
if (reset = '0') then
count <= "0000";
elsif(rising_edge(clk)) then
if (enable = '1') then
if (load = '0') then
if (up = '1') then
if count = "1001" then
count <= "0000";
else
count <= count + 1;
end if;
else
if count = "0000" then
count <= "1001";
else
count <= count - 1;
end if;
end if;
else
count <= d;
end if;
end if;
end if;
end process;
q <= count;
end architecture;
Mô phỏng
Wave form
I,.Thí nghiệm 3.2 - Bộ đếm lên xuống thập phân từ 0-99
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity bodem99 is
port(
d0,d1: in std_logic_vector (3 downto 0);
enable,load,up,clr,clk: in std_logic;
q0,q1: out std_logic_vector (3 downto 0);
co1: out std_logic
);
end entity;
architecture structure of bodem99 is
signal c : std_logic;
component bodemmaBCD
port(
enable, load, up, reset, clk: in std_logic;
d: in std_logic_vector(3 downto 0);
co: out std_logic;
q: out std_logic_vector(3 downto 0)
);
end component;
begin
u1: bodemmaBCD port map (enable,load,up,clr,clk,d0,c,q0);
u2: bodemmaBCD port map (enable,load,up,clr,c,d1,co1,q1);
end architecture;
Mô phỏng
Wave form