Advertisement
LucaSkywalker

PS2.vhd

Jan 10th, 2021
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.60 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5. entity PS2 is port(     PS2C: in STD_LOGIC;
  6.                         PS2D: in STD_LOGIC;
  7.                         AN : out STD_LOGIC_VECTOR (3 DOWNTO 0);
  8.                         LED : out STD_LOGIC_VECTOR (7 DOWNTO 0);
  9.                         SEG : out STD_LOGIC_VECTOR (6 DOWNTO 0));
  10. end PS2;
  11.  
  12. architecture BEHAVIORAL of PS2 is
  13.     begin
  14.     MAIN: process(PS2C)
  15.     variable State : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
  16.     variable Data : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000";
  17.     begin
  18.         AN(3 DOWNTO 0) <= "1110";
  19.         if falling_edge(PS2C) then
  20.             if State = "0000" then
  21.                 if PS2D = '0' then --start
  22.                     State := State + 1;
  23.                     Data(7 DOWNTO 0) := "00000000";
  24.                 end if;
  25.             elsif State = "0001" then --D0
  26.                 Data(0) := PS2D;
  27.                 State := State + 1;
  28.             elsif State = "0010" then --D1
  29.                 Data(1) := PS2D;
  30.                 State := State + 1;
  31.             elsif State = "0011" then --D2
  32.                 Data(2) := PS2D;
  33.                 State := State + 1;
  34.             elsif State = "0100" then --D3
  35.                 Data(3) := PS2D;
  36.                 State := State + 1;
  37.             elsif State = "0101" then --D4
  38.                 Data(4) := PS2D;
  39.                 State := State + 1;
  40.             elsif State = "0110" then --D5
  41.                 Data(5) := PS2D;
  42.                 State := State + 1;
  43.             elsif State = "0111" then --D6
  44.                 Data(6) := PS2D;
  45.                 State := State + 1;
  46.             elsif State = "1000" then --D7
  47.                 Data(7) := PS2D;
  48.                 State := State + 1;
  49.             elsif State = "1001" then --Parity
  50.                 State := State + 1;
  51.             elsif State = "1010" then --stop
  52.                 State := "0000";
  53.             end if;
  54.             case Data is
  55.                 when "00011100" =>  SEG(6 DOWNTO 0) <= "0000010";     --A
  56.                 when "00110010" =>  SEG(6 DOWNTO 0) <= "0000100";     --B
  57.                 when "00100001" =>  SEG(6 DOWNTO 0) <= "0110001";     --C
  58.                 when "00100011" =>  SEG(6 DOWNTO 0) <= "1000010";     --D
  59.                 when "00100100" =>  SEG(6 DOWNTO 0) <= "0110000";     --E
  60.                 when "00101011" =>  SEG(6 DOWNTO 0) <= "0111000";     --F
  61.                 when "01000101" =>  SEG(6 DOWNTO 0) <= "0000001";     --0
  62.                 when "00010110" =>  SEG(6 DOWNTO 0) <= "1001111";   --1
  63.                 when "00011110" =>  SEG(6 DOWNTO 0) <= "0010010";     --2
  64.                 when "00100110" =>  SEG(6 DOWNTO 0) <= "0000110";     --3
  65.                 when "00100101" =>  SEG(6 DOWNTO 0) <= "1001100";     --4
  66.                 when "00101110" =>  SEG(6 DOWNTO 0) <= "0100100";     --5
  67.                 when "00110110" =>  SEG(6 DOWNTO 0) <= "0100000";   --6
  68.                 when "00111101" =>  SEG(6 DOWNTO 0) <= "0001111";   --7
  69.                 when "00111110" =>  SEG(6 DOWNTO 0) <= "0000000";   --8
  70.                 when "01000110" =>  SEG(6 DOWNTO 0) <= "0000100";   --9
  71.                 when others =>      SEG(6 DOWNTO 0) <= "1111111";   -- any other key
  72.             end case;
  73.             LED(7 DOWNTO 0) <= Data;
  74.         end if;
  75.     end process;
  76. end BEHAVIORAL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement