Professional Documents
Culture Documents
Dap An TH - VMS
Dap An TH - VMS
Câu 1: Thiết kế bộ đếm tiến thập phân, kết quả hiển thị LED 7 thanh bằng phương
pháp máy trạng thái
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau1 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (7 downto 0));
end cau1;
entity cau7 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (15 downto 0));
end cau7;
dem:process(clk,rst)
variable d_tam: integer range 0 to 15:=0;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam=15 then d_tam:=0;
else d_tam:=d_tam+1;
end if;
end if;
end if;
d <= d_tam;
end process;
mahoa:process(d)
begin
case d is
when 0 => Q <= "0000000000000001";
when 1 => Q <= "0000000000000010";
when 2 => Q <= "0000000000000100";
when 3 => Q <= "0000000000001000";
when 4 => Q <= "0000000000010000";
when 5 => Q <= "0000000000100000";
when 6 => Q <= "0000000001000000";
when 7 => Q <= "0000000010000000";
when 8 => Q <= "0000000100000000";
when 9 => Q <= "0000001000000000";
when 10 => Q <= "0000010000000000";
when 11 => Q <= "0000100000000000";
when 12 => Q <= "0001000000000000";
when 13 => Q <= "0010000000000000";
when 14 => Q <= "0100000000000000";
when 15 => Q <= "1000000000000000";
when others => Q <= "XXXXXXXXXXXXXXXX";
end case;
end process;
Câu 8: Thiết kế mạch đếm theo mã Johnson 8 bit , kết quả hiển thị LED đơn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau8 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (7 downto 0));
end cau8;
dem:process(clk,rst)
variable d_tam: integer range 0 to 15:=0;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam = 15 then d_tam:=0;
else d_tam:=d_tam+1;
end if;
end if;
end if;
d<=d_tam;
end process;
mahoa:process(d)
begin
case d is
when 0 => Q <= "00000000";
when 1 => Q <= "00000001";
when 2 => Q <= "00000011";
when 3 => Q <= "00000111";
when 4 => Q <= "00001111";
when 5 => Q <= "00011111";
when 6 => Q <= "00111111";
when 7 => Q <= "01111111";
when 8 => Q <= "11111111";
when 9 => Q <= "11111110";
when 10 => Q <= "11111100";
when 11 => Q <= "11111000";
when 12 => Q <= "11110000";
when 13 => Q <= "11100000";
when 14 => Q <= "11000000";
when 15 => Q <= "10000000";
when others => Q <= "XXXXXXXX";
end case;
end process;
end Behavioral;
Câu 9: Thiết kế bộ đếm tiến các số chẵn từ 0 100 theo mã nhị phân, kết quả hiển
thị LED đơn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
entity cau9 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (6 downto 0));
end cau9;
dem:process(clk,rst)
variable d_tam: integer range 0 to 100:=0;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam rem 2 = 0 then
if d_tam =100 then d_tam:=0;
else d_tam:=d_tam+2;
end if;
end if;
end if;
end if;
Q<= conv_std_logic_vector(d_tam,7);
end process;
end Behavioral;
Câu 10: Thiết kế bộ đếm lùi các số lẻ từ 99 1 theo mã nhị phân, kết quả hiển thị
LED đơn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
entity cau10 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (6 downto 0));
end cau10;
dem:process(clk,rst)
variable d_tam: integer range 1 to 99;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam rem 2 /= 0 then
if d_tam =1 then d_tam:=99;
else d_tam:= d_tam-2;
end if;
end if;
end if;
end if;
Q<=conv_std_logic_vector(d_tam,7);
end process;
end Behavioral;
Câu 11: Thiết kế bộ đếm tiến, thập phân cho phép chọn đếm chẵn hoặc đếm lẻ, kết
quả hiển thị LED 7 thanh
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
entity cau11 is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
A : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (7 downto 0));
end cau11;
c1:process(clk,rst)
variable d_tam: integer range 0 to 8;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam = 8 then d_tam:=0;
else d_tam:=d_tam+1;
end if;
end if;
end if;
d<=d_tam;
end process;
c2:process(d)
begin
case d is
when 0 => Q <= "0000000000000000";
when 1 => Q <= "0000000110000000";
when 2 => Q <= "0000001111000000";
when 3 => Q <= "0000011111100000";
when 4 => Q <= "0000111111110000";
when 5 => Q <= "0001111111111000";
when 6 => Q <= "0011111111111100";
when 7 => Q <= "0111111111111110";
when 8 => Q <= "1111111111111111";
when others => Q <= "XXXXXXXXXXXXXXXX";
end case;
end process;
end Behavioral;
Câu 15: Thiết kế mạch điều khiển 16 LED đơn sáng lan từ 2 bên về giữa theo
phương pháp máy trạng thái
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau15 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (15 downto 0));
end cau15;
c1:process(clk,rst)
begin
if rst='1' then s<=s0;
else
if clk'event and clk='1' then
case s is
when s0=>s<=s1;
when s1=>s<=s2;
when s2=>s<=s3;
when s3=>s<=s4;
when s4=>s<=s5;
when s5=>s<=s6;
when s6=>s<=s7;
when s7=>s<=s8;
when others =>s<=s0;
end case;
end if;
end if;
end process;
c2:process(s)
begin
case s is
when s0 => Q <= "0000000000000000";
when s1 => Q <= "1000000000000001";
when s2 => Q <= "1100000000000011";
when s3 => Q <= "1110000000000111";
when s4 => Q <= "1111000000001111";
when s5 => Q <= "1111100000011111";
when s6 => Q <= "1111110000111111";
when s7 => Q <= "1111111001111111";
when others => Q <= "1111111111111111";
end case;
end process;
end Behavioral;
Câu 16: Thiết kế bộ đếm theo mã Gray 4 bit, kết quả hiển thị LED đơn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau16 is
Port ( rst : in STD_LOGIC;
clock : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (3 downto 0));
end cau16;
dem:process(rst,clk)
variable d_tam: integer range 0 to 15;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam=15 then d_tam:=0;
else d_tam:=d_tam+1;
end if;
end if;
end if;
d<=d_tam;
end process;
mahoa:process(d)
begin
case d is
when 0 => Q <= "0000";
when 1 => Q <= "0001";
when 2 => Q <= "0011";
when 3 => Q <= "0010";
when 4 => Q <= "0110";
when 5 => Q <= "0111";
when 6 => Q <= "0101";
when 7 => Q <= "0100";
when 8 => Q <= "1100";
when 9 => Q <= "1101";
when 10 => Q <= "1111";
when 11 => Q <= "1110";
when 12 => Q <= "1010";
when 13 => Q <= "1011";
when 14 => Q <= "1001";
when others => Q <= "1000";
end case;
end process;
end Behavioral;
Câu 17: Thiết kế mạch điều khiển đèn giao thông. Yêu cầu đèn đỏ sáng 10s, đèn
xanh sáng 7s, đèn vàng sáng 3s, số giây được đếm ngược về 0 và hiển thị trên LED
7 thanh
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau17 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (2 downto 0);
led7 : out STD_LOGIC_VECTOR (7 downto 0));
end cau17;
c1:process(clk,rst)
variable d_tam: integer range 0 to 19;
begin
if rst='1' then d_tam:=0;
else
if clk'event and clk='1' then
if d_tam=19 then d_tam:=0;
else d_tam:=d_tam+1;
end if;
end if;
end if;
d<=d_tam;
end process;
c2:process(d)
begin
case d is
when 0 =>led7<= x"90";Q<="100";
when 1 =>led7<= x"80";Q<="100";
when 2 =>led7<= x"f8";Q<="100";
when 3 =>led7<= x"82";Q<="100";
when 4 =>led7<= x"92";Q<="100";
when 5 =>led7<= x"99";Q<="100";
when 6 =>led7<= x"b0";Q<="100";
when 7 =>led7<= x"a4";Q<="100";
when 8 =>led7<= x"f9";Q<="100";
when 9 =>led7<= x"c0";Q<="100";
when 10 =>led7<= x"82";Q<="010";
when 11 =>led7<= x"92";Q<="010";
when 12 =>led7<= x"99";Q<="010";
when 13 =>led7<= x"b0";Q<="010";
when 14 =>led7<= x"a4";Q<="010";
when 15 =>led7<= x"f9";Q<="010";
when 16 =>led7<= x"c0";Q<="010";
when 17 =>led7<= x"a4";Q<="001";
when 18 =>led7<= x"f9";Q<="001";
when others =>led7<= x"c0";Q<="001";
end case;
end process;
end Behavioral;
Câu 18: Thiết kế thanh ghi dịch vào nối tiếp, ra song song 8 bít bằng phương pháp
sử dụng proccess
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau18 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
D : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (7 downto 0));
end cau18;
begin
c1:process(A,B,Cin)
begin
tam(0) <= A(0)xor B(0) xor Cin;
c(0) <= (B(0) and Cin) or ((not A(0)) and (B(0) xor Cin));
end process;
c2:process(A,B,C)
begin
tam(1) <= A(1)xor B(1) xor C(0);
c(1) <= (B(1) and C(0)) or ((not A(1)) and (B(1) xor C(0)));
end process;
c3:process(A,B,C)
begin
tam(2) <= A(2)xor B(2) xor C(1);
Cout <= (B(2) and C(1)) or ((not A(2)) and (B(2) xor C(1)));
end process;
c4:process(tam)
begin
case tam is
when "000" =>led<=x"c0";
when "001" =>led<=x"f9";
when "010" =>led<=x"a4";
when "011" =>led<=x"b0";
when "100" =>led<=x"99";
when "101" =>led<=x"92";
when "110" =>led<=x"82";
when others =>led<=x"f8";
end case;
end process;
end Behavioral;
Câu 21: Thiết kế và mô phỏng mạch cộng đầy đủ 3 bit sử dụng component là bộ
cộng đầy đủ 1 bit. Kết quả hiển thị dạng nhị phân trên LED đơn.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau21 is
Port ( A : in STD_LOGIC_VECTOR (2 downto 0);
B : in STD_LOGIC_VECTOR (2 downto 0);
Cin : in STD_LOGIC;
Cout : out STD_LOGIC;
led : out STD_LOGIC_VECTOR (2 downto 0));
end cau21;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cong1 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
Cout : out STD_LOGIC;
out1 : out STD_LOGIC );
end cong1;
begin
process(A,B,Cin)
begin
out1 <= A xor B xor Cin;
Cout <= ((B and Cin) or(A and (B xor Cin)));
end process;
end Behavioral;
Câu 22: Cho hai số đầu vào A, B (3 bit). Thiết kế mạch điện thực hiện một trong
các chức năng: A+B; A+1; B+1 tùy theo giá trị của đầu vào lựa chọn chức năng.
Kết quả hiển thị trên LED đơn và LED 7 thanh
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity cau22 is
Port ( A : in STD_LOGIC_VECTOR (2 downto 0);
B : in STD_LOGIC_VECTOR (2 downto 0);
C : in STD_LOGIC_VECTOR (1 downto 0);
led : out STD_LOGIC_VECTOR (3 downto 0);
led7 : out STD_LOGIC_VECTOR (7 downto 0));
end cau22;
end process;
mahoa:process(s)
begin
case s is
when s0=>Q<="00000";
when s2=>Q<="00010";
when s4=>Q<="00100";
when s6=>Q<="00110";
when s8=>Q<="01000";
when s10=>Q<="01010";
when s12=>Q<="01100";
when s14=>Q<="01110";
when s16=>Q<="10000";
when s18=>Q<="10010";
when others =>Q<="10100";
end case;
end process;
end Behavioral;
Câu 27: Thiết kế DFF. Sử dụng DFF như component để thiết kế thanh ghi dịch vào
nối tiếp, ra song song
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity main is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
D : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (7 downto 0));
end main;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity DFF is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
d : in STD_LOGIC;
out1 : out STD_LOGIC);
end DFF;
begin
process(clk,rst,d)
begin
if rst = '1' then out1<= '0';
elsif clk'event and clk='1' then
out1<= d;
end if;
end process;
end Behavioral;
Câu 28: Thiết kế JKFF. Sử dụng JKFF như component để thiết kế bộ đếm tiến nhị
phân 4 bít
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity main is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
J : in STD_LOGIC;
K : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (3 downto 0));
end main;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_arith.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity JK is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
j : in STD_LOGIC;
k : in STD_LOGIC;
out1 : out STD_LOGIC);
end JK;
architecture Behavioral of JK is
signal tg : STD_LOGIC:='0';
begin
process(clk,rst,j,k)
begin
if rst ='1' then tg <= '0';
elsif clk'event and clk='1' then
tg <= (j and not(tg)) or (tg and not(k));
end if;
out1<=tg;
end process;
end Behavioral;
Câu 29: Thiết kế mạch điều khiển máy pha café tự động: chờ khởi động( 1đèn
xanh sáng) trộn café và sữa trong 2s ( 2 đèn xanh sáng) hòa tan café+ sữa+
nước trong 5s (3 đèn xanh sáng) kết thúc (đèn đỏ sáng 1s)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity cau29 is
Port ( clock : in STD_LOGIC;
rst : in STD_LOGIC;
X : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR (3 downto 0));
end cau29;