集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1536|回复: 0

PS2键盘控制实验

[复制链接]
lichangyun 发表于 2010-10-19 16:45:56 | 显示全部楼层 |阅读模式
这是一个主机和键盘的双向通讯的实验,扫描码在四个数码管上显示,其中包括分频电路,键盘电路和显示电路,在分频和键盘电路上存有疑惑和问题,恳请大家帮忙。分频电路为:
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);
--   shift1(0)<=data;
--        shift1(10 downto 1)<=shift1(9 downto 0);
--        shift2(0)<=shift1(10);
--        shift2(10 downto 1)<=shift2(9 downto 0);

end if;
end if;
end process;

end Behavioral;
哪位高手能给解析一下这个程序?谢谢!
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-18 16:46 , Processed in 0.118522 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表