在 VHDL (Spartan 3) 的 2 个七段显示器上显示不同的数字

Displaying different numbers on 2 seven segment displays on VHDL (Spartan 3)

我们有一个关于解码的作业。 4个输入开关(二进制组合)和显示对应的开关组合为4-LED和十进制数值为1个七段。并将这些二进制组合转换为格雷码(也是4位)并将相应的4-LED和十进制值显示为1个七段。

我已经有了 K-Mapping 的解决方案,但我的主要问题是在两个段上打印不同的数字。我的问题是它显示了最后解析的代码。他们对七段有相同的输出。

这是我的代码..

entity BinaryToGrey is
    Port ( Bin : in  STD_LOGIC_VECTOR (3 downto 0);
              BinLed: out STD_LOGIC_VECTOR (3 downto 0);
              Enable: in STD_LOGIC_VECTOR (3 downto 0);
              Segment: out STD_LOGIC_VECTOR (6 downto 0);
           Grey : inout  STD_LOGIC_VECTOR (3 downto 0));
end BinaryToGrey;

architecture Behavioral of BinaryToGrey is

begin

Grey(3) <= Bin(3);
Grey(2) <= Bin(3) XOR Bin(2);
Grey(1) <= Bin(2) XOR Bin(1);
Grey(0) <= Bin(1) XOR Bin(0);

    process(Bin)

begin
case Bin is
when "0000"=> BinLed <="0000";  -- '0'
        when "0001"=> BinLed <="0001";  -- '1'
        when "0010"=> BinLed <="0010";  -- '2'
        when "0011"=> BinLed <="0011";  -- '3'
        when "0100"=> BinLed <="0100";  -- '4' 
        when "0101"=> BinLed <="0101";  -- '5'
        when "0110"=> BinLed <="0110";  -- '6'
        when "0111"=> BinLed <="0111";  -- '7'
        when "1000"=> BinLed <="1000";  -- '8'
        when "1001"=> BinLed <="1001";  -- '9'
        when "1010"=> BinLed <="1010";  -- 'A'
        when "1011"=> BinLed <="1011";  -- 'b'
        when "1100"=> BinLed <="1100";  -- 'C'
        when "1101"=> BinLed <="1101";  -- 'd'
        when "1110"=> BinLed <="1110";  -- 'E'
        when others => BinLed <="1111"; -- 'F'
    end case;
    end process;


process(Bin,Enable)
begin
        Enable(0) = '0';
        Enable(1) = '1';
        Enable(2) = '1';
        Enable(3) = '0';
        case Bin is 
        when "0000"=> Segment <="1111110";  -- '0'
        when "0001"=> Segment <="0110000";  -- '1'
        when "0010"=> Segment <="1101101";  -- '2'
        when "0011"=> Segment <="1111001";  -- '3'
        when "0100"=> Segment <="0110011";  -- '4' 
        when "0101"=> Segment <="1011011";  -- '5'
        when "0110"=> Segment <="1011111";  -- '6'
        when "0111"=> Segment <="1110000";  -- '7'
        when "1000"=> Segment <="1111111";  -- '8'
        when "1001"=> Segment <="1111011";  -- '9'
        when "1010"=> Segment <="1110111";  -- 'A'
        when "1011"=> Segment <="0011111";  -- 'b'
        when "1100"=> Segment <="1001110";  -- 'C'
        when "1101"=> Segment <="0111101";  -- 'd'
        when "1110"=> Segment <="1001111";  -- 'E'
        when others => Segment <="1001011"; -- 'F'
    end case;

end process;


process(Grey,Enable)
begin

    Enable(0) = '0';
    Enable(1) = '1';
    Enable(2) = '1';
    Enable(3) = '0';
    case Grey is 
        when "0000"=> Segment <="1111110";  -- '0'
        when "0001"=> Segment <="0110000";  -- '1'
        when "0010"=> Segment <="1101101";  -- '2'
        when "0011"=> Segment <="1111001";  -- '3'
        when "0100"=> Segment <="0110011";  -- '4' 
        when "0101"=> Segment <="1011011";  -- '5'
        when "0110"=> Segment <="1011111";  -- '6'
        when "0111"=> Segment <="1110000";  -- '7'
        when "1000"=> Segment <="1111111";  -- '8'
        when "1001"=> Segment <="1111011";  -- '9'
        when "1010"=> Segment <="1110111";  -- 'A'
        when "1011"=> Segment <="0011111";  -- 'b'
        when "1100"=> Segment <="1001110";  -- 'C'
        when "1101"=> Segment <="0111101";  -- 'd'
        when "1110"=> Segment <="1001111";  -- 'E'
        when others => Segment <="1001011"; -- 'F'
    end case;

    end if;
end process;


end Behavioral;

代码中有几处错误。

1) Enable是一个输入,但是有赋值给它。如果该信号用于选择 7 段显示,则它必须是输出。

Enable: out STD_LOGIC_VECTOR (3 downto 0);

2) 两个进程驱动同一个 Segment 信号。分配应该在一个进程中,并且应该是多路复用的。

创建一个 Select 信号并在每个时钟周期切换它。您还需要一个时钟输入。 (注:我没有展示Select信号的产生)

process(Bin,Grey)
begin

if (Select = '0') then -- Select one display

        Enable(0) <= '0';
        Enable(1) <= '1';
        Enable(2) <= '0';
        Enable(3) <= '0';
        case Bin is 
        when "0000"=> Segment <="1111110";  -- '0'
        when "0001"=> Segment <="0110000";  -- '1'
        when "0010"=> Segment <="1101101";  -- '2'
        when "0011"=> Segment <="1111001";  -- '3'
        when "0100"=> Segment <="0110011";  -- '4' 
        when "0101"=> Segment <="1011011";  -- '5'
        when "0110"=> Segment <="1011111";  -- '6'
        when "0111"=> Segment <="1110000";  -- '7'
        when "1000"=> Segment <="1111111";  -- '8'
        when "1001"=> Segment <="1111011";  -- '9'
        when "1010"=> Segment <="1110111";  -- 'A'
        when "1011"=> Segment <="0011111";  -- 'b'
        when "1100"=> Segment <="1001110";  -- 'C'
        when "1101"=> Segment <="0111101";  -- 'd'
        when "1110"=> Segment <="1001111";  -- 'E'
        when others => Segment <="1001011"; -- 'F'
    end case;

else -- Select the other display

    Enable(0) <= '0';
    Enable(1) <= '0';
    Enable(2) <= '1';
    Enable(3) <= '0';
    case Grey is 
        when "0000"=> Segment <="1111110";  -- '0'
        when "0001"=> Segment <="0110000";  -- '1'
        when "0010"=> Segment <="1101101";  -- '2'
        when "0011"=> Segment <="1111001";  -- '3'
        when "0100"=> Segment <="0110011";  -- '4' 
        when "0101"=> Segment <="1011011";  -- '5'
        when "0110"=> Segment <="1011111";  -- '6'
        when "0111"=> Segment <="1110000";  -- '7'
        when "1000"=> Segment <="1111111";  -- '8'
        when "1001"=> Segment <="1111011";  -- '9'
        when "1010"=> Segment <="1110111";  -- 'A'
        when "1011"=> Segment <="0011111";  -- 'b'
        when "1100"=> Segment <="1001110";  -- 'C'
        when "1101"=> Segment <="0111101";  -- 'd'
        when "1110"=> Segment <="1001111";  -- 'E'
        when others => Segment <="1001011"; -- 'F'
    end case;

end if;

end process;

3) 在一个时钟周期内仅断言 Enable 信号的一位,并使用 <= 进行分配。我假设 Enable 是高电平有效。如果不是,请适当更改值。

选择显示1时:

Enable(0) <= '0';
Enable(1) <= '1';
Enable(2) <= '0';
Enable(3) <= '0';

选择显示2时:

Enable(0) <= '0';
Enable(1) <= '0';
Enable(2) <= '1';
Enable(3) <= '0';

4) Enable 信号不应出现在敏感列表中。我把两个进程合并后应该是这样的

process(Bin,Grey)