首页 > 解决方案 > 7 段显示器上数字 0000 到 0099 的 VHDL 代码

问题描述

我是 VHDL 的初学者,试图根据我按下的开关在我的板 (BASYS-3) 上编写从 0000 到 0099 的代码。问题是,我需要一个开关来打开和关闭程序,4 个开关用于显示最右边的十进制数字,另外 4 个用于显示“十”(如 17 中的 1)。板上有更多开关(总共 16 个),但我认为 4 个是最合乎逻辑的,因为十进制的二进制编码(比如二进制中的 9 = 1001 是最大的)。

我不知道要使用什么门,所以我所做的工作非常有限,对此感到抱歉。

process(bcd_display)

begin

    case bcd_display is

    when "0000" => LED <= "0000001";     

    when "0001" => LED <= "1001111"; 

    when "0010" => LED <= "0010010"; 

    when "0011" => LED <= "0000110"; 

    when "0100" => LED <= "1001100"; 

    when "0101" => LED <= "0100100"; 

    when "0110" => LED <= "0100000"; 

    when "0111" => LED <= "0001111"; 

    when "1000" => LED <= "0000000";     

    when "1001" => LED <= "0000100"; 

    end case;

end process;

PS:https ://www.youtube.com/watch?v=H7a56D4rczU 最后 30 秒左右显示了我正在尝试做的事情。英语不是我的第一语言,所以我把它放在一边,以防我的描述难以理解。

标签: vhdlxilinxvivado

解决方案


为了将来参考,您将要添加完整的代码和您正在使用的测试平台。我仍然写了我认为对你有用的东西。对于下面。您需要将每个开关分配给 ( bcd_display_0& bcd_display_1)。要重置程序,请将该开关分配给 ( rst),然后您需要将时钟分配给 ( clk)。然后将七段显示器中的每一个分配给 ( LED_0& LED_1)。希望这能让你继续前进。我还为你附上了一个测试台。

-- BCD Entity
library ieee;
use ieee.std_logic_1164.all;

entity Display_Test is
    port (
        clk           : in  std_logic;
        rst           : in  std_logic;
        bcd_display_0 : in  std_logic_vector(3 downto 0);-- assign to first set of switches
        bcd_display_1 : in  std_logic_vector(3 downto 0);-- assign to second set of switches
        LED_0         : out std_logic_vector(6 downto 0);-- assign to first 7-segment display
        LED_1         : out std_logic_vector(6 downto 0) -- assign to second 7-segment display
    );
end Display_Test;

architecture behav of Display_Test is
    use ieee.numeric_std.all;
begin
    p : process(clk)
    begin
        if rising_edge(clk) then
            if rst = '1' then 
                LED_0 <= (others => '0');
                LED_1 <= (others => '0');
            else
                case to_integer(unsigned(bcd_display_0)) is
                    when 0 => LED_0 <= "0000001";     
                    when 1 => LED_0 <= "1001111"; 
                    when 2 => LED_0 <= "0010010"; 
                    when 3 => LED_0 <= "0000110"; 
                    when 4 => LED_0 <= "1001100"; 
                    when 5 => LED_0 <= "0100100"; 
                    when 6 => LED_0 <= "0100000"; 
                    when 7 => LED_0 <= "0001111"; 
                    when 8 => LED_0 <= "0000000";     
                    when 9 => LED_0 <= "0000100"; 
                    when others => LED_0 <= "0000000";
                end case;

                case to_integer(unsigned(bcd_display_1)) is
                    when 0 => LED_1 <= "0000001";     
                    when 1 => LED_1 <= "1001111"; 
                    when 2 => LED_1 <= "0010010"; 
                    when 3 => LED_1 <= "0000110"; 
                    when 4 => LED_1 <= "1001100"; 
                    when 5 => LED_1 <= "0100100"; 
                    when 6 => LED_1 <= "0100000"; 
                    when 7 => LED_1 <= "0001111"; 
                    when 8 => LED_1 <= "0000000";     
                    when 9 => LED_1 <= "0000100"; 
                    when others => LED_1 <= "0000000";
                end case;
            end if;
        end if;
    end process;
end behav;

--TestBench
entity tb_bcd is
end tb_bcd;

library ieee;
use ieee.std_logic_1164.all;

architecture behav of tb_bcd is
   signal clk           : std_logic := '1';
   signal rst           : std_logic := '1';
   signal bcd_display_0 : std_logic_vector(3 downto 0);
   signal bcd_display_1 : std_logic_vector(3 downto 0);
   signal LED_0         : std_logic_vector(6 downto 0);
   signal LED_1         : std_logic_vector(6 downto 0);
begin
    clk           <= not clk after 50 ns;
    rst           <= '0' after 200 ns;
    bcd_display_0 <= "0110" after 250 ns;
    bcd_display_1 <= "0010" after 280 ns;

    Display_Test_inst : entity work.Display_Test
        port map (
            clk           => clk,
            rst           => rst,
            bcd_display_0 => bcd_display_0,
            bcd_display_1 => bcd_display_1,
            LED_0         => LED_0,
            LED_1         => LED_1
        );
end behav;

推荐阅读