1、与非门VHDL:
library ieee;
use ieee.std_logic_1164.all;
entity nand_2 is
port(a,b:in std_logic;
y:out std_logic);
end;
architecture one of nand_2 is
begin
y<=a nand b;
end;
2、或非门VHDL:
代码一:
library ieee;
use ieee.std_logic.1164.all;
entity nor_2 is
port(a,b:in std_logic;
y:out std_logic);
end;
architecture one of nor_2 is
begin
y<=a nor b;
end;
代码二:
library ieee;
use ieee.std_logic.1164.all;
entity nor_2 is
port(a,b:in std_logic;
y:out std_logic);
end;
architecture one of nor_2 is
signal ab :std_logic_vector(1 downto 0);
begin
ab<=a&b;
process(ab) is
begin
case ab is
when "00"=>y<="1";
when "01"=>y<="0";
when "10"=>y<="0";
when "11"=>y<="0";
when others=>null;
end case;
end process;
end;
3、异或门VHDL:
library ieee;
use ieee.std_logic.1164.all;
entity xor_2 is
port(a,b:in std_logic;
y:out std_logic);
end;
architecture one of xor_2 is
begin
y<=a xor b;
end;
4、三态门电路:三态门是指逻辑门的输出状态除了高低电平两种状态外,还有第三种状态---高阻态的门电路,高阻态相当于隔断状态。三态门都有一个en使能控制端,用来控制门电路的通断。
library ieee;
use ieee.std_logic.1164.all;
entity tri_gate is
port(din:in std_logic;----信号输出端
en: in std_logic;----使能端
dout:out std_logic);--信号输出端
end;
architecture one of tri_gate is
begin
dout<=din when en='1' else 'Z';
end;
5、单相总线缓冲器:单相总线缓冲器与三态门类似,只不过输出输出端均为总线形式。
LIBRARY ieee;
USE ieee.std_logic_1164.all;
-- Entity Declaration
ENTITY tri_buffer IS
-- {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
PORT
(
din : IN STD_LOGIC_VECTOR(7 downto 0);
en : IN STD_LOGIC;
dout : OUT STD_LOGIC_VECTOR(7 downto 0)
);
-- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!
END tri_buffer;
-- Architecture Body
ARCHITECTURE tri_buffer_architecture OF tri_buffer IS
BEGIN
process(en,din)
begin
if en='1'then dout<=din;
else dout<="ZZZZZZZZ";
end if;
end process;
END tri_buffer_architecture;
6、双向总线缓冲器:双向总线缓冲器的两个数据端口均为双向端口(inout),除了使能信号外还有一个数据方向控制端口。
LIBRARY ieee;
USE ieee.std_logic_1164.all;
-- Entity Declaration
ENTITY tri_bibuffer IS
-- {{ALTERA_IO_BEGIN}} DO NOT REMOVE THIS LINE!
PORT
(
en : IN STD_LOGIC;
dr : IN STD_LOGIC;
a : INOUT STD_LOGIC_VECTOR(7 downto 0);
b : INOUT STD_LOGIC_VECTOR(7 downto 0)
);
-- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!
END tri_bibuffer;
-- Architecture Body
ARCHITECTURE tri_bibuffer_architecture OF tri_bibuffer IS
signal a_out,b_out:std_logic_vector(7downto 0);
BEGIN
PROCESS(a,b_out,en,dr)
begin
if en='1' and dr='1' then b_out<=a;
else b_out<="ZZZZZZZZ";
end if;
b<=b_out;
end process;
PROCESS(a,b_out,en,dr)
begin
if en='1' and dr='0' then a_out<=b;
else a_out<="ZZZZZZZZ";
end if;
a<=a_out;
end process;
END tri_bibuffer_architecture;
参考资料:《基于Quartsu II的FPGA/CPLD数字系统设计实例》
周润景 图雅 张丽敏 编著
文章评论(0条评论)
登录后参与讨论