上一篇写的是常用门电路设计范例,这一篇写常用组合逻辑电路的设计。
1、编码器:8-3线编码器:(VHDL)
library ieee;
use ieee.std_logic.1164.all;
entity bianma8_3 is
port(i:in std_logic_vector(7 downto 0);
y:out std_logic_vector(2 downto 0));
end;
architecture one of bianma8_3 is
begin
process(i)
begin
case i is
when "00000001"=>y=<"000";
when "00000010"=>y=<"001";
when "00000100"=>y=<"010";
when "00001000"=>y=<"011";
when "00010000"=>y=<"100";
when "00100000"=>y=<"101";
when "01000000"=>y=<"110";
when "10000000"=>y=<"111";
when others=>y<="000";
end case;
end process;
end;
2、译码器:3-8线译码器:(VHDL)
library ieee;
use ieee.std_logic.1164.all;
entity decoder3_8 is
port(y:out std_logic_vector(7 downto 0);
a:in std_logic_vector(2 downto 0);
g1,g2,g3:in std_logic);
end;
architecture one of decoder3_8 is
begin
process(a,g1,g2,g3)
begin
if g1='0' then y<="11111111";
elsif g2='1' or g3='1' then y<="11111111";
esle
case a is
when "000"=>y=<"11111110";
when "001"=>y=<"11111101";
when "010"=>y=<"11111011";
when "011"=>y=<"11110111";
when "100"=>y=<"11101111";
when "101"=>y=<"11011111";
when "110"=>y=<"10111111";
when "111"=>y=<"01111111";
when others=>y<="11111111";
end case;
end if;
end process;
end;
3、数据选择器:数据选择器经过选择,把多个通道的数据传到唯一的公共数据通道上去的功能。
4选1数据选择器:(VHDL)
library ieee;
use ieee.std_logic_1164.all;
entity mux4 is
port(d0,d1,d2,d3:in std_logic;---4个数据源
g:in std_logic;----使能端
a: in std_logic_vector(1 downto 0);---两位地址码
y:out std_logic);---选择输出端
end;
architecture one of mux4 is
begin
process(a,g,d0,d1,d2,d3)
begin
if g='0' then y<='0';
else
case a is
when "00"=>y<=d0;
when "01"=>y<=d1;
when "10"=>y<=d2;
when "11"=>y<=d3;
when others=>y<='0';
end case;
end if;
end process;
end;
4、数据分配器:数据分配器与数据选择器的功能相反,数据分配器是将一个数据源的数据根据需要送到多个不同的通道上去。
1对4数据分配器:(VHDL)
library ieee;
use ieee.std_logic_1164.all;
entity demux4 is
port(y0,y1,y2,y3:out std_logic;---4个数据通道
a: in std_logic_vector(1 downto 0);---两位地址码
din:in std_logic);---选择输入端
end;
architecture one of demux4 is
begin
process(a,din)
begin
y0<='0';
y1<='0';
y2<='0';
y3<='0';
case a is
when "00"=>y<=din;
when "01"=>y<=din;
when "10"=>y<=din;
when "11"=>y<=din;
when others=>y<=null;
end case;
end process;
end;
5、数据比较器:(VHDL)
library ieee;
use ieee.std_logic_1164.all;
entity comparator_4 is
port(y1,y2,y3:out std_logic;-----比较结果
a,b: in std_logic_vector(3 downto 0));----数据输入端
end;
architecture one of comparator_4 is
begin
process(a,b)
begin
if a>b then
y1<='1';
y2<='0';
y3<='0';
elsif a=b then
y1<='0';
y2<='1';
y3<='0';
elsif a<b then
y1<='0';
y2<='0';
y3<='1';
end if;
end process;
end;
6、半加器:半加器只是考虑了两个加数本身,而没有考虑来自地位的进位,所以称之为半加。(VHDL)
library ieee;
use ieee.std_logic_1164.all;
entity half_add is
port(s,c:out std_logic;
a,b: in std_logic);
end;
architecture one of half_add is
begin
s<=a xor b;
c<=a and b;
end;
还有全加器,半减器,全减器,多位的加法或者减法器,这里不在一一赘述,大家可以自己查阅相关资料自己来完成。
参考资料:《基于Quartsu II的FPGA/CPLD数字系统设计实例》
周润景 图雅 张丽敏 编著
文章评论(0条评论)
登录后参与讨论