【发布时间】:2018-10-23 15:08:05
【问题描述】:
我想在 4 位 7 段显示器上显示 3 位二进制,并按下适当的开关。 例如:- 如果开关位置为 001(switch2-off switch1-off switch0-on) 然后我想在 7 段显示器上显示 001。 我使用 VHDL 来做这件事。 尝试了多路复用,但仍然无法正常工作。 下面是代码。
entity test is
Port(Seg_AN :out std_logic_vector(3 downto 0);
Seg7 :out std_logic_vector(6 downto 0);
SWITCH :in std_logic_vector(2 downto 0);
CLK :in std_logic
);
end test;
architecture Behavioral of test is
signal sel :natural range 0 to 8;
signal anode_sel :std_logic_vector(2 downto 0);
-- signal number :std_logic_vector(2 downto 0);
constant c_cnt_200hz :natural := 87500;
-- constant c_cnt_1hz :natural := 17500000;
signal r_cnt_200hz :natural range 0 to c_cnt_200hz;
-- signal r_cnt_1hz :natural range 0 to c_cnt_1hz;
signal anode :std_logic_vector(2 downto 0);
signal segment :std_logic_vector(6 downto 0);
-- signal digit :std_logic;
begin
process(CLK)
begin
if rising_edge(CLK) then
if r_cnt_200hz = c_cnt_200hz - 1 then
r_cnt_200hz <= 0;
if sel = 8 then
sel <= 0;
else
sel <= sel + 1;
end if;
else
r_cnt_200hz <= r_cnt_200hz + 1;
end if;
end if;
end process;
process(sel)
begin
case sel is
when 1 => anode_sel <= "001";
when 2 => anode_sel <= "010";
when 3 => anode_sel <= "100";
when 4 => anode_sel <= "011";
when 5 => anode_sel <= "101";
when 6 => anode_sel <= "110";
when others => anode_sel <= "111";
end case;
anode <= not anode_sel;
end process;
process(anode)
begin
if SWITCH(0)='1' or SWITCH(1)='1' or SWITCH(2)='1' then
segment <= "1111001";
else
segment <= "1000000";
end if;
end process;
Seg_AN <= '1' & anode;
Seg7 <= segment;
end Behavioral;
【问题讨论】:
-
您只需要在显示 0 和 1 之间切换即可控制 4 个段:0= 段打开,1= 段关闭。除了三位的所有 VHDL 头文件、库实体等之外,您可以使用三行代码来完成。
-
@Oldfart 请你说清楚。
-
使用 4 Khz 时钟(c_cnt_200hz = 20,用于更快的仿真)。 Note more than one anode (Seg_AN) is on at a time。显示 0 还是 1 取决于启用的阳极和相应的开关。 still not working 不是一个明确的问题陈述。你在问什么?
标签: vhdl fpga seven-segment-display