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

时间:2017-07-12 17:19:29

标签: vhdl xilinx-ise spartan

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

我已经有了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 个答案:

答案 0 :(得分:1)

代码中有几个错误。

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)