selinoktay
selinoktay

Reputation: 19

VHDL Code For Numbers 0000 to 0099 on 7-Segment Display

I'm a beginner to VHDL, trying to write a code that counts from 0000 to 0099 on my board (BASYS-3) depending on which switches I press. Problem is, I need one switch for shutting the program on and off, 4 switches for showing the far right decimal digit and 4 other for showing the "tens" (like the 1 in 17). There are more switches on the board (in total 16) but I thought 4 is most logical because of the binary codings of decimals (like 9 = 1001 in binary is the largest).

I have no idea on what gates to use so the work I've done is very limited, sorry about that.

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 The last 30 seconds or so shows what I'm trying to do. English is not my first language so I'm putting this in case my description was hard to understand.

Upvotes: 0

Views: 2717

Answers (1)

Laburtz
Laburtz

Reputation: 90

For future reference, you are going to want to add full code & the testbench you are using. I still wrote out what I think will work for you. For below. You will want to assign each switch to (bcd_display_0 & bcd_display_1). For resetting the program, assign that switch to (rst) and you will need to assign a clock to (clk). Then assign each the seven segment displays to (LED_0 & LED_1). Hopefully this gets you going. I have also attached a test bench for you.

-- 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;

Upvotes: 1

Related Questions