library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cn8 is
port(clk:in std_logic;
cout:out std_logic_vector(2 downto 0));
end cn8;
architecture rtl of cn8 is
signal q: std_logic_vector(2 downto 0);
begin
process(clk)
begin
if (clk'event and clk='1' ) then
if (q=7) then
q<="000";
else
q<=q+1;
end if;
end if;
end process;
cout<=q;
end rtl;
1.3.2 3-8线译码器模块
library ieee;
use ieee.std_logic_1164.all;
entity decoder3_8 is
port(a:in std_logic_vector(2 downto 0);
q:out std_logic_vector(7 downto 0));
end decoder3_8;
architecture rtl of decoder3_8 is
begin
process(a)
begin
case a is
when "000"=>q<="11111110";
when "001"=>q<="11111101";
when "010"=>q<="11111011";
when "011"=>q<="11110111";
when "100"=>q<="11101111";
when "101"=>q<="11011111";
when "110"=>q<="10111111";
when others=>q<="01111111";
end case;
end process;
end rtl;
1.3.3 八选一数据选择模块
library ieee;
use ieee.std_logic_1164.all;
entity sel81 is
port(sel:in std_logic_vector(2 downto 0);
a,b,c,d,e,f,g,h:in std_logic_vector(3 downto 0);
q:out std_logic_vector(3 downto 0));
end sel81;
architecture rtl of sel81 is
begin
process(a,b,c,d,e,f,g,h,sel)
variable cout: std_logic_vector(3 downto 0);
begin
case (sel) is
when "000"=>cout:=a;
when "001"=>cout:=b;
when "010"=>cout:=c;
when "011"=>cout:=d;
when "100"=>cout:=e;
when "101"=>cout:=f;
when "110"=>cout:=g;
when others=>cout:=h;
end case;
q<=cout;
end process;
end rtl;
1.3.4 七段译码器模块
library ieee;
use ieee.std_logic_1164.all;
entity disp is
port(d:in std_logic_vector(3 downto 0);
q:out std_logic_vector(6 downto 0));
end disp;
architecture rtl of disp is
begin
process(d)
begin
case d is
when"0000"=>q<="0111111";
when"0001"=>q<="0000110";
when"0010"=>q<="1011011";
when"0011"=>q<="1001111";
when"0100"=>q<="1100110";
when"0101"=>q<="1101101";
when"0110"=>q<="1111101";
when"0111"=>q<="0100111";
when"1000"=>q<="1111111";
when others=>q<="1101111";
end case;
end process;
end rtl;
1.3.5 驱动八位数码管显示的整体电路