tong hop cac bai tap vhdl - Pdf 95

BAI 1:
1>DFF dong bo rst.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty DFF_DONGBO is
port(
CLK : in STD_LOGIC;
D : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC
);
end DFF_DONGBO;
architecture DFF_DONGBO of DFF_DONGBO is
begin
process(d,clk,rst)
begin
if (rst='1')and (clk'event and clk='1') then
q<='0' ;
elsif clk'event and clk='1' then
q<=d;
end if;
end process;
end DFF_DONGBO;
2> DFF khong dong bo rst.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty DFF_KHONGDONGBO is
port(
D : in STD_LOGIC;
RST : in STD_LOGIC;
CLK : in STD_LOGIC;

variable A: std_logic:='0';
begin
y <=r&s;
if rst='1' then
q<='0';
elsif clk'event and clk='1' then
if y="00" then
q<=a;
elsif y="10" then
q<='0' ;
elsif y="01" then
q<='1' ;
elsif y="11" then
q<='X';
end if;
end if;
end process;
end RSFF;
4> RSFF dong bo.
architecture RSFF_DONGBO of RSFF_DONGBO is
signal y: std_logic_vector(1 downto 0);
begin
process(r,s,clk,rst)
variable A: std_logic:='0';
begin
y <=r&s;
if (rst='1') AND (clk'event and clk='1') then
q<='0';
elsif clk'event and clk='1' then
if y="00" then

Q(4)<= D and ((C(2)) and (not(C(1)) and not(C(0))));
Q(5)<= D and ((C(2)) and (not(C(1)) and (C(0))));
Q(6)<= D and ((C(2)) and ((C(1)) and not(C(0))));
Q(7)<= D and ((C(2)) and ((C(1)) and (C(0))));
end process;
end DEMUX8_1;
2> Thiet ke mach giai gray.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty gm_7seg is
port(
en : in STD_LOGIC;
a : in STD_LOGIC_VECTOR(2 downto 0);
b : out STD_LOGIC_VECTOR(2 downto 0)
);
end gm_7seg;
architecture gm_7seg of gm_7seg is
begin
process(a,en)
begin
case A is
when "000"=>b<="000";
when"001"=>b<="001";
when"010"=>b<="011";
when"011"=>b<="010";
when "100"=>b<="100";
when"101"=>b<="101";
when"110"=>b<="111";
when"111"=>b<="110";
when others=>b<="XXX";

end sscach2;
4. mach giai ma 7 doan.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty machgiaima7doan is
port(
a : in STD_LOGIC_VECTOR(3 downto 0);
y : out STD_LOGIC_VECTOR(7 downto 0)
);
end machgiaima7doan;
architecture machgiaima7doan of machgiaima7doan is
begin
process(a)
begin
case a is
when "0000"=>y<="01000000";
when "0001"=>y<="01111001";
when "0010"=>y<="00100100";
when "0011"=>y<="00110000";
when "0100"=>y<="00011001";
when "0101"=>y<="00010010";
when "0110"=>y<="00000010";
when "0111"=>y<="01111000";
when "1000"=>y<="00000000";
when "1001"=>y<="00010000";
when others =>y<="XXXXXXXX" ;
end case;
end process;
end machgiaima7doan;
5. bo ALU 4 bit;

else
Q<=conv_std_logic_vector(chuyen(A)/chuyen(B),5);
end if;
end if;
End Process;
end ALU;
BAI3:
1. DEM TIEN LUI KD=16;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.std_logic_arith.all;
en$ty demkd_16_dungconv is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR(3 downto 0)
);
end demkd_16_dungconv;
architecture demkd_16_dungconv of demkd_16_dungconv is
begin
process(s,clk,rst)
variable x:integer range 0 to 15:=0;
begin
if rst='1' then
x:=0;
elsif clk'event and clk='1' then
if s='1' then
if x=15 then
x:=0;

begin
if rst='1' then
x:=0;
elsif clk'event and clk='1' then
if s='1' then
if x=15 then
x:=0;
else
x:=x+1;
end if;
else
if x=0 then
x:=15;
else
x:=x-1;
end if;
end if;
end if;
y<=conv_std_logic_vector(x,4);
end process;
end demkd_16_dungconv;
3.ghi dich vao nt ra ss
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty ghidichvaont_ss is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
d : in STD_LOGIC;
y : out STD_LOGIC_VECTOR(7 downto 0)

end gray4bit;
architecture gray4bit of gray4bit is
begin
process(rst,clk)
variable a : integer range 0 to 15 ;
begin
if rst='1' then
Q<="0000";
elsif clk'event and clk='1' then
if a=15 then
a:=0;
else
a:=a+1;
end if;
end if;
case a 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";

end case;
end if;
end process;
output: process(s)
begin
case s is
when s0=>y<="0001";
when s1=>y<="0010";
when s2=>y<="0100";
when s3=>y<="1000";
when others =>y<="XXXX";
end case;
end process;
end mavong4bit;
3.thiet ke den gia thong.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_arith.all;
en$ty dengthong is
port(
clk : in STD_LOGIC;
rst : in STD_LOGIC;
v : out STD_LOGIC;
x : out STD_LOGIC;
d : out STD_LOGIC;
ht : out STD_LOGIC_VECTOR(7 downto 0)
);
end dengthong;
architecture dengthong of dengthong is
signal z: std_logic_vector(4 downto 0);

when 3=>ht<="00110000";
when 4=>ht<="00011001";
when 5=>ht<="00010010";
when 6=>ht<="00000001";
when 7=>ht<="01111000";
when 8=>ht<="00000000";

when 9=>ht<="01000000";
when 10=>ht<="01111001";
when 11=>ht<="01000100";
when 12=>ht<="00110000";
when 13=>ht<="00011001";
when 14=>ht<= "00010010";

when 15=>ht<="01000000";
when 16=>ht<="01111001";
when 17=>ht<="01000100";
when others =>ht<="XXXXXXXX";
end case;
z<=conv_std_logic_vector(a,5) ;
end process;
end dengthong;
4.kta dau vao la 1000 thi ra =1;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
en$ty ktr_sdmang is
port(
clk : in STD_LOGIC;
rst : in STD_LOGIC;
d :in std_logic;


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status