BCD到bargraph解码器的vhdl设计代码

时间:2015-10-01 13:32:11

标签: vhdl hdl

输入表示0到9之间的二进制值。有九个输出。每个输出驱动一个LED。当输出为0时,其关联的LED为ON。当它为1时,其关联的LED为OFF。 LED堆叠在垂直条中。顶部LED由bar_graph(8)驱动,底部LED由bar_graph(0)驱动。

我在这里粘贴了我的代码并且它有一些错误,我不确定这是否是正确的方法。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;

entity bcd_2_bar is 

port (bcd : in std_logic_vector (3 downto 0); 

  bar_graph : out std_logic_vector (8 downto 0)); 

end bcd_2_bar; 

architecture test of bcd_2_bar is

begin

  bar_graph<="111111111" when "0000" else 

  bar_graph<="111111110" when "0001" else

  bar_graph<="111111100" when "0010" else

  bar_graph<="111111000" when "0011" else

  bar_graph<="111110000" when "0100" else 

  bar_graph<="111100000" when "0101" else

  bar_graph<="111000000" when "0110" else

  bar_graph<="110000000" when "0111" else

  bar_graph<="100000000" when "1000" else 

  --nothing is displayed when number greater than nine.

  bar_graph<="111111111" when others;

end test;

2 个答案:

答案 0 :(得分:0)

您尚未撰写格式正确的声明。您可以执行以下操作之一:

bar_graph <= "111111111" when bcd = "0000" else
             "111111110" when bcd = "0001" else
             "111111100" when bcd = "0010" else
             "111111000" when bcd = "0011" else
             "111110000" when bcd = "0100" else
             "111111111";

with bcd select bar_graph <=
             "111111111" when "0000",
             "111111110" when "0001",
             "111111100" when "0010",
             "111111000" when "0011",
             "111110000" when "0100",
             "111111111" when others;

process(bcd)
begin
  case bcd is
    when "0000" => bar_graph <= "111111111";
    when "0001" => bar_graph <= "111111110";
    when "0010" => bar_graph <= "111111100";
    when "0011" => bar_graph <= "111111000";
    when "0100" => bar_graph <= "111110000";
    when others => bar_graph <= "111111111";
  end case;
end process;

我没有包含你所有的bcd值,但你应该明白这一点。

答案 1 :(得分:0)

或类似的东西

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std_unsigned.all;

entity bcd_2_bar is
  generic (
    led_on : std_logic := '0');
  port (
    bcd       : in  std_logic_vector(3 downto 0);
    bar_graph : out std_logic_vector(8 downto 0));
end entity bcd_2_bar;

architecture rtl of bcd_2_bar is
begin
  led_driver: process (bcd) is
  begin
    for led in bar_graph'range loop
      bar_graph(led) <= not led_on when bcd > bar_graph'length else
                        led_on when led < bcd else
                        not led_on;
    end loop;
  end process led_driver;
end architecture rtl;