Processeur/Processeur.srcs/sources_1/new/KeyboardDriver.vhd

90 lines
2.7 KiB
VHDL

----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 13.07.2021 09:30:08
-- Design Name:
-- Module Name: KeyboardDriver - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.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 leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity KeyboardDriver is
Generic (Nb_Bits : Natural);
Port (CLK : in STD_LOGIC;
Data_read : out STD_LOGIC;
Data_av : in STD_LOGIC;
Data : in STD_LOGIC_VECTOR (0 to 6);
STD_IN : out STD_LOGIC_VECTOR (Nb_Bits - 1 downto 0);
STD_IN_Av : out STD_LOGIC;
STD_IN_Request : in STD_LOGIC;
STD_OUT : out STD_LOGIC_VECTOR (Nb_Bits - 1 downto 0);
STD_OUT_Av : out STD_LOGIC);
end KeyboardDriver;
architecture Behavioral of KeyboardDriver is
signal intern_value : Natural := 0;
signal work_in_progress : BOOLEAN := false;
signal Zeros : STD_LOGIC_Vector (Nb_bits - 1 downto 7) := (others => '0');
begin
process
begin
wait until CLK'event and CLK = '1';
STD_IN_Av <= '0';
STD_OUT_Av <= '0';
if not(work_in_progress) then
intern_value <= 0;
end if;
if STD_IN_Request = '1' then
work_in_progress <= true;
if Data_av = '1' then
if (Data = "1111111") then
intern_value <= intern_value / 10;
STD_OUT <= Zeros & Data;
STD_OUT_Av <= '1';
elsif (Data = "0001010") then
STD_IN <= std_logic_vector(to_unsigned(intern_value, Nb_bits));
STD_IN_Av <= '1';
work_in_progress <= false;
STD_OUT <= Zeros & Data;
STD_OUT_Av <= '1';
elsif (Data >= "0110000" and Data <= "0111001") then
intern_value <= intern_value * 10 + to_integer(unsigned(Data(3 to 6)));
STD_OUT <= Zeros & Data;
STD_OUT_Av <= '1';
end if;
end if;
end if;
end process;
Data_read <= '0' when STD_IN_Request = '0' else Data_av;
end Behavioral;