📄 data_scanc.vhd
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity data_scanC is
PORT(
sys_clk : in STD_LOGIC; --系统同步时钟
k_data : in STD_LOGIC; --键盘数据
k_clock : in STD_LOGIC; --键盘时钟
reset : in STD_LOGIC;
data : out STD_LOGIC_VECTOR(7 DOWNTO 0); --扫描码输出
PA : buffer STD_LOGIC_VECTOR(7 DOWNTO 0);
ZHJS : buffer STD_LOGIC --扫描码转换结束信号
);
end data_scanC;
architecture behav of data_scanC is
signal tmp : STD_LOGIC_VECTOR(11 downto 0) :="000000000000";--用来记录一帧信号
signal ENABLE : std_logic :='0'; --输出使能
signal now_kbclk,pre_kbclk : std_logic;
begin
process(reset,k_clock,sys_clk)
variable started:STD_LOGIC :='0';
variable counter :integer range 0 to 11 :=0;
begin
if reset='0' then ZHJS<='0';counter:=0;
elsif rising_edge(sys_clk) then
pre_kbclk <= now_kbclk;
now_kbclk <= k_clock;
if(pre_kbclk > now_kbclk) then --因为按键比较容易出现抖动导致不稳定,这里加个
tmp(counter)<=k_data; --时钟判断,这样就比较稳定了。
if counter=10 then ZHJS<='0';
else ZHJS<='1';
end if;
if counter=11 then counter:=1;
else counter:=counter+1;
end if;
end if;
end if;
if(counter>1 and counter<10) then started:='1';
else started:='0';
end if;
enable<=started;
end process;
PA<="00000000" when enable='1' else tmp(8 downto 1);
data<=PA;
end behav;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -