我在第 35 行得到了 case 语句必须涵盖表达式的所有可能值,“Case 显示计数器是”
如果您在代码中发现任何其他错误,请告诉我。
这是下面代码的键入版本
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SimonGame is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
btn1, btn2, btn3, btn4 : in STD_LOGIC;
hex_0, hex_1, hex_2 : out STD_LOGIC_VECTOR(6 downto 0));
end SimonGame;
architecture Behavioral of SimonGame is
signal sequence : STD_LOGIC_VECTOR(2 downto 0);
signal count : INTEGER := 0;
signal display_counter : INTEGER := 0;
signal correct_input : BOOLEAN := TRUE;
type Digit_State is (DISPLAY_SEQUENCE, AWAIT_INPUT);
signal state : Digit_State := DISPLAY_SEQUENCE;
begin
process(clk, rst)
begin
if rst = '1' then
sequence <= "001"; -- Initial sequence
count <= 0;
display_counter <= 0;
state <= DISPLAY_SEQUENCE;
elsif rising_edge(clk) then
case state is
when DISPLAY_SEQUENCE =>
-- Display the sequence on hex_0 and hex_1
case display_counter is
when 0 =>
hex_0 <= "0000001";
hex_1 <= "0000000";
when 1 =>
hex_0 <= "0001000";
hex_1 <= "0000000";
when 2 =>
hex_0 <= "0000100";
hex_1 <= "0000000";
when 3 =>
hex_0 <= "0000010";
hex_1 <= "0000000";
when 4 =>
hex_0 <= "0001000";
hex_1 <= "0000000";
when 5 =>
hex_0 <= "0000001";
hex_1 <= "0000000";
state <= AWAIT_INPUT;
end case;
if display_counter < 5 then
display_counter <= display_counter + 1;
else
display_counter <= 0;
count <= count + 1;
sequence <= sequence(0) & sequence(2 downto 1); -- Shift the sequence
end if;
when AWAIT_INPUT =>
-- Check button input against the sequence
if btn1 = '1' then
correct_input <= (sequence = "001");
elsif btn4 = '1' then
correct_input <= (sequence = "010");
elsif btn3 = '1' then
correct_input <= (sequence = "100");
elsif btn2 = '1' then
correct_input <= (sequence = "010");
else
correct_input <= FALSE;
end if;
if correct_input then
state <= DISPLAY_SEQUENCE;
end if;
end case;
end if;
end process;
end Behavioral;
case
语句必须始终涵盖变量可以采用的所有可能值。在你的情况下 0 <= display_counter
<= 5 is covered, but what if display_counter
小于 0 还是大于 5?您必须告诉您的程序在这些情况下该怎么做。总体结构如下:
case my_variable is
when value1 =>
-- do something for value1
when value2 =>
-- do something for value2
when others =>
-- default action when my_variable doesn't match any defined case
end case;