PS2键盘控制实验 这是一个主机和键盘的双向通讯的实验,扫描码在四个数码管上显示,其中包括分频电路,键盘电路和显示电路,在分频和键盘电路上存有疑惑和问题,恳请大家帮忙。分频电路为: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity divclk is port( clk : in std_logic; ------50MHZ clk400 : out std_logic; -------400KHZ scanclk : out std_Logic ); end divclk;
architecture Behavioral of divclk is
begin
process(clk) variable count : std_logic_vector(19 downto 0):=X"00000"; begin if(rising_edge(clk))then count:=count+1; end if; clk400<=count(2); scanclk<=count(12); end process;
end Behavioral; 在此程序中是怎么得到400KHZ和25HZ的? 键盘的程序如下: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity key_board is port( clr : in std_logic; clk400 : in std_logic; --400KHZ ps2clk : in std_logic; ps2data : in std_logic; dataout : out std_logic_vector(15 downto 0) ); end key_board;
architecture Behavioral of key_board is signal clk : std_logic:='0'; signal data : std_logic:='0'; signal shift1,shift2 : std_logic_vector(10 downto 0); signal ps2c,ps2d : std_logic; begin ps2c<=ps2clk; ps2d<=ps2data; dataout<=shift1(8 downto 1) & shift2(8 downto 1); process(clk400,clr) variable tempclk : std_logic_vector(7 downto 0):=X"00"; variable tempdata: std_logic_vector(7 downto 0):=X"00"; begin if(clr='0') then tempclk:=X"00"; tempdata:=X"00"; clk<='0'; data<='0'; else if(clk400'event and clk400='1') then tempclk(0):=ps2c; tempclk(7 downto 1):=tempclk(6 downto 0); tempdata(0):=ps2d; tempdata(7 downto 1):=tempdata(6 downto 0); end if; end if;
if(tempclk="11111111") then clk<='1'; else if(tempclk="00000000") then clk<='0'; end if; end if;
if(tempdata="11111111") then data<='1'; else if(tempdata="00000000") then data<='0'; end if; end if;
end process; process(clk,clr) begin if(clr='0')then shift1<=(others => '0'); shift2<=(others => '0'); else if(clk'event and clk='0') then shift1(10)<=data; shift1(9 downto 0)<=shift1(10 downto 1); shift2(10)<=shift1(0); shift2(9 downto 0)<=shift2(10 downto 1); end if; end if; end process;