verilog编写的键盘扫描程序
-- keyscan
--Author:ZHANGXiangyang
--Data:20080401
------------------------------------------
--4*4按键,两个四位一体数码管,显示的时候全部显示相同的字,是一个简单的版本,还没有添加消抖,添加之后再发,
--因为开始自己 学习的时候也遇到很多困难,希望能对大家有所帮助.
--编程的时候一定要结合自己的硬件结构
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity keyscantest is
port(
col
utstd_logic_vector(3 downto 0);--接四列
clk:in std_logic; --时钟,频率范围:
led
ut std_logic_vector(6 downto 0);--接七段数码管
row:in std_logic_vector(3 downto 0));--接四行
end keyscantest;
architecture behave of keyscantest is
signal count :std_logic_vector(3 downto 0);--计数
begin
a1:process(clk)
begin
if(clk'event and clk='1')then--时钟上升沿计数
count<=count+1;
end if;
end process a1;
c1:process(clk)
begin
if(clk'event and clk='1')then
if(count=1)then
col<="0010"; --第一列置高电平
if(row="0001"
then --读入第一行,若为高,显示"0"
led<="0111111";
elsif(row="0010"
then
led<="1100110";
elsif(row="0100"
then
led<="1111111";
elsif(row="1000")then
led<="0111001";
else
led<="0000000";
end if;
elsif(count=2)then
col<="0100";
if(row="0001")then
led<="0000110";
elsif(row="0010")then
led<="1101101";
elsif(row="0100")then
led<="1101111";
elsif(row="1000")then
led<="1011110";
else
led<="0000000";
end if;
elsif(count=3)then
col<="1000";
if(row="0001")then
led<="1011011";
elsif(row="0010")then
led<="1111101";
elsif(row="0100")then
led<="1110111";
elsif(row="1000")then
led<="1111001";
else
led<="0000000";
end if;
elsif(count=4)then
col<="0001";
if(row="0001")then
led<="1001111";
elsif(row="0010")then
led<="0000111";
elsif(row="0100")then
led<="1111100";
elsif(row="1000")then
led<="1110001";
else
led<="0000000";
end if;
end if;
end if;
end process c1;
end behave; |