填空这是用4个拨码开关的16种组合来代表16个4位二进制数,控制一个共阴极7段数码管的显示程序,请补充完整。 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity led7 is Port ( a: in STD_LOGIC_VECTOR ( 1 downto 0); c: in STD_LOGIC; led7s: out STD_LOGIC_VECTOR (6 downto 0); y: out STD_LOGIC); end led7; architecture Behavioral of led7 is begin process (a) begin case a ( 3 downto 0 ) is when "0000"=> led7s<= "0111111"; when "0001"=> led7s<= "0000110"; when "0010"=> led7s<= "1011011"; when "0011"=> led7s<= "1001111"; when 2 => led7s<= "1100110"; when "0101"=> led7s<= "1101101"; when "0110"=> led7s<= "1111101"; when "0111"=> led7s<= "0000111"; when "1000"=> led7s<= "1111111"; when "1001"=> led7s<= "1101111"; when "1010"=> led7s<= "1110111"; when "1011"=> led7s<= "1111100"; when "1100"=> led7s<= "0111001"; when "1101"=> led7s<= "1011110"; when "1110"=> led7s<= "1111001"; when "1111"=> led7s<= "1110001"; when 3 => null; end case; end process; Y<=C; end Behavioral;
时间: 2023-12-05 21:18:13 浏览: 69
填空后的完整代码如下:
```
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity led7 is
Port ( a: in STD_LOGIC_VECTOR (3 downto 0);
c: in STD_LOGIC;
led7s: out STD_LOGIC_VECTOR (6 downto 0);
y: out STD_LOGIC);
end led7;
architecture Behavioral of led7 is
begin
process (a)
begin
case a is
when "0000" => led7s <= "0111111";
when "0001" => led7s <= "0000110";
when "0010" => led7s <= "1011011";
when "0011" => led7s <= "1001111";
when "0100" => led7s <= "1100110";
when "0101" => led7s <= "1101101";
when "0110" => led7s <= "1111101";
when "0111" => led7s <= "0000111";
when "1000" => led7s <= "1111111";
when "1001" => led7s <= "1101111";
when "1010" => led7s <= "1110111";
when "1011" => led7s <= "1111100";
when "1100" => led7s <= "0111001";
when "1101" => led7s <= "1011110";
when "1110" => led7s <= "1111001";
when "1111" => led7s <= "1110001";
when others => led7s <= "0111111"; -- 默认显示 0
end case;
end process;
y <= c;
end Behavioral;
```
在原代码中,有两处需要填空,分别是:
1. 在 `a` 的 `STD_LOGIC_VECTOR` 中,需要将 `downto` 改为 `to`,因为 `a` 的长度为 4,应该从 0 到 3 进行索引。
2. 在 `case` 语句中,需要将 "2" 和 "3" 的分支填上默认值,否则会产生语法错误。
因此,修改后的代码中,在第 9 行将 `downto` 改为 `to`,在第 23 行和第 28 行分别添加 `when others` 的分支,表示对于其他值,显示 0,以保证程序的正确性。
阅读全文