Вот для примера сделал реализацию простого интерфейса опроса клавиатуры:
Схема:
Вложение 33296
Код:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity keyb is
port(
CLK : in std_logic;
C : in std_logic_vector(3 downto 0);
R : out std_logic_vector(3 downto 0);
SCAN0 : out std_logic_vector(7 downto 0);
SCAN1 : out std_logic_vector(7 downto 0);
KEY : out std_logic
);
end keyb;
architecture keyb of keyb is
type state_t is (s_idle, s0, s1, s2, s3);
signal state : state_t := s_idle;
signal row : std_logic_vector(3 downto 0) := "0000";
signal data0 : std_logic_vector(3 downto 0) := "1111";
signal data1 : std_logic_vector(3 downto 0) := "1111";
signal data2 : std_logic_vector(3 downto 0) := "1111";
signal data3 : std_logic_vector(3 downto 0) := "1111";
signal K : std_logic;
begin
process (CLK)
begin
if CLK'event and CLK = '1' then
if state = s_idle then
row <= "0000";
data0 <= "1111";
data1 <= "1111";
data2 <= "1111";
data3 <= "1111";
if K /= '1' then
row <= "1110";
state <= s0;
end if;
elsif state = s0 then
if K /= '1' then
data0 <= C;
end if;
row <= "1101";
state <= s1;
elsif state = s1 then
if K /= '1' then
data1 <= C;
end if;
row <= "1011";
state <= s2;
elsif state = s2 then
if K /= '1' then
data2 <= C;
end if;
row <= "0111";
state <= s3;
elsif state = s3 then
if K /= '1' then
data3 <= C;
end if;
row <= "0000";
state <= s_idle;
end if;
end if;
end process;
K <= C(3) and C(2) and C(1) and C(0);
R <= row;
SCAN0 <= data0 & data1;
SCAN1 <= data2 & data3;
KEY <= K;
end keyb;
Моделирование:
Вложение 33297