1

首先对不起我的英语不好,希望你能理解我的问题

我有一个项目“定时炸弹”。我使用键盘和 Nexys 3 FPGA。我必须单击两个数字,例如 1 和 2,并通过键盘上定义的数字或字母进行确认。然后它必须在 7 段显示器上显示并开始倒计时到 0。12,11,10,9... 0。单击数字 (0-9) 并显示它没有问题,但是问题是当我想显示两位数(10-99)时。我按 1 并确定它显示在两个 7 段显示器上。然后我按 2 并在两段显示器上显示,但我只想在一个上显示。所以我有结果 22 但我想看到 21 或 12 这取决于我们假设的约定。两个评论的过程是我们尝试这样做但没有奏效。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity mojaklaw is
    Port (SEG : out std_logic_vector(6 downto 0);  -- segmenty wyświetlacza 
                         DP : out std_logic; -- kropki na wyswietlaczu
                         ENABLE : out std_logic_vector(3 downto 0); -- anody wyswietlacza
                         CLK : in std_logic; -- zegar
                         ROW : in std_logic_vector(3 downto 0); -- rzad klawiatury
                         COL : buffer std_logic_vector(3 downto 0); -- kolumna klawiatury
                         LEDS : out std_logic_vector(3 downto 0) ); -- diody led

end mojaklaw;

architecture Behavioral of mojaklaw is
signal Q : std_logic_vector(22 downto 0); -- 4-bitowy licznik sterujacy
signal KeyCode : std_logic_vector(3 downto 0); -- kod przycisku klawiatury
signal KeyCode1 : std_logic_vector(3 downto 0); -- kod przycisku klawiatury 2
signal DIGIT : std_logic_vector(3 downto 0); -- konwersja kodu klawiatury
signal En : std_logic; -- '0' oznacza wcisniety przycisk klawiatury




begin
DP<='1'; -- wygaszenie kropek (dots turn off)


process(CLK) begin -- 4-bit COUNTER
if rising_edge(CLK) then
if En='1' then Q<=Q+1; end if;
end if;
end process;


with Q(20 downto 19) select -- MUX
En<= ROW(0) when "00", ROW(1) when "01", ROW(2) when "10", ROW(3) when "11", '1' when others;
with Q(22 downto 21) select -- DECODER
COL<= "1110" when "00", "1101" when "01", "1011" when "10", "0111" when "11", "1111" when others;


--process(CLK) begin -- REGISTER
--if rising_edge(CLK) then
--if En='0' then KeyCode<=Q(22 downto 19); Q2<='1'; end if;
--if Q2='1' then if En='0' then KeyCode1<=KeyCode; end if;
--else KeyCode1<="1111"; end if;
--end if;
----end process;

--process (CLK) 
-- variable Q2 : integer;
--begin
--if rising_edge(CLK) then
--if Q2=1 then
--if En='0' then KeyCode1<=KeyCode; Q2:=0; end if;
--else 
--if En='0' then KeyCode<=Q(22 downto 19); Q2:=1; end if;
--end if; -- if Q2
--end if; -- if edge
--end process;

process(CLK) begin -- REGISTER keycode
if rising_edge(CLK) then
if En='0' then KeyCode<=Q(22 downto 19); 
end if; end if;
end process;



-- MUX 7SEGMENT LCD
with Q(17 downto 16) select 
DIGIT <= KeyCode when "00", KeyCode1 when "01", "1111" when "10", "1111" when others;


-- CONVERTER 7SEGMENT LCD konwersja kodu klawiatury na wyswietlacz 7segmentowy
process(DIGIT) begin
case DIGIT is
when "0011" => SEG <= "0000001"; -- 0
when "0000" => SEG <= "1001111"; -- 1
when "0100" => SEG <= "0010010"; -- 2
when "1000" => SEG <= "0000110"; -- 3
when "0001" => SEG <= "1001100"; -- 4
when "0101" => SEG <= "0100100"; -- 5
when "1001" => SEG <= "0100000"; -- 6
when "0010" => SEG <= "0001111"; -- 7
when "0110" => SEG <= "0000000"; -- 8
when "1010" => SEG <= "0000100"; -- 9
when others => SEG <= "1111111"; -- -
end case;
end process;

-- DECODER 7SEGMENT LCD
with Q(17 downto 16) select
ENABLE <= "1110" when "00", "1101" when "01",
"1011" when "10", "0111" when others ;


end Behavioral;

这是我们的 PIN 分配:

NET "CLK" LOC="V10"; # CLK

NET "COL(3)" LOC="H3"; # JC1
NET "COL(2)" LOC="L7"; # JC2
NET "COL(1)" LOC="K6"; # JC3
NET "COL(0)" LOC="G3"; # JC4
NET "ROW(3)" LOC="G1"; # JC7
NET "ROW(2)" LOC="J7"; # JC8
NET "ROW(1)" LOC="J6"; # JC9
NET "ROW(0)" LOC="F2"; # JC10


NET "SEG(6)" LOC="T17"; # A
NET "SEG(5)" LOC="T18"; # B
NET "SEG(4)" LOC="U17"; # C
NET "SEG(3)" LOC="U18"; # D
NET "SEG(2)" LOC="M14"; # E
NET "SEG(1)" LOC="N14"; # F
NET "SEG(0)" LOC="L14"; # G
NET "DP" LOC="M13"; #DP

NET "ENABLE(3)" LOC="P17"; #AN3
NET "ENABLE(2)" LOC="P18"; #AN2
NET "ENABLE(1)" LOC="N15"; #AN1
NET "ENABLE(0)" LOC="N16"; #AN0



NET "LEDS(3)" LOC="V15"; # LD3
NET "LEDS(2)" LOC="U15"; # LD2
NET "LEDS(1)" LOC="V16"; # LD1
NET "LEDS(0)" LOC="U16"; # LD0 
4

0 回答 0