vhdl键盘程序,帮忙看一下
发布网友
发布时间:2022-05-05 09:29
我来回答
共2个回答
热心网友
时间:2022-06-27 06:43
以手机键盘为例子写的
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY keyboard IS
PORT( clk:IN STD_LOGIC;
keyin:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
keyout:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
led:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));
END keyboard;
ARCHITECTURE bhv OF keyboard IS
SIGNAL start:STD_LOGIC;
SIGNAL tmp:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
p1:PROCESS(keyin,clk)
BEGIN
IF clk'EVENT AND clk='1' THEN
IF keyin/="111" THEN start<='1';
ELSE start<='0';
END IF;
END IF;
END PROCESS p1;
p2:PROCESS(start,clk,keyin,tmp)
VARIABLE count:STD_LOGIC_VECTOR(1 DOWNTO 0);
VARIABLE tmp1:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
IF start='1' THEN
IF clk'EVENT AND clk='1' THEN count:=count+1;
ELSE NULL;
END IF;
CASE count IS
WHEN "00" =>keyout<="0111";
CASE keyin IS
WHEN "011" to "110" =>tmp1:="0001";
-- WHEN "101" =>tmp1:="0010";
-- WHEN "110" =>tmp1:="0011";
WHEN OTHERS=>tmp1:="1100";
END CASE;
WHEN "01" =>keyout<="1011";
CASE keyin IS
WHEN "011" =>tmp1:="0100";
WHEN "101" =>tmp1:="0101";
WHEN "110" =>tmp1:="0110";
WHEN OTHERS=>tmp1:="1100";
END CASE;
WHEN "10" =>keyout<="1101";
CASE keyin IS
WHEN "011" =>tmp1:="0111";
WHEN "101" =>tmp1:="1000";
WHEN "110" =>tmp1:="1001";
WHEN OTHERS=>tmp1:="1100";
END CASE;
WHEN "11" =>keyout<="1110";
CASE keyin IS
WHEN "011" =>tmp1:="1110";
WHEN "101" =>tmp1:="0000";
WHEN "110" =>tmp1:="1111";
WHEN OTHERS=>tmp1:="1100";
END CASE;
WHEN OTHERS => keyout<="ZZZZ";
END CASE;
ELSE keyout<="ZZZZ";tmp1:="1100";
END IF;
tmp<=tmp1;
END PROCESS p2;
--以下是译码电路
p3:PROCESS(tmp)
BEGIN
CASE tmp IS
WHEN "0001" => led<="0110000";
WHEN "0010" => led<="1011011";
WHEN "0011" => led<="1001111";
WHEN "0100" => led<="1100110";
WHEN "0101" => led<="1101101";
WHEN "0110" => led<="1111101";
WHEN "0111" => led<="0000111";
WHEN "1000" => led<="1111111";
WHEN "1001" => led<="1101111";
WHEN "1110" => led<="1001001"; -- 以 --- 代替显示 *
WHEN "0000" => led<="0111111";
WHEN "1111" => led<="0110110"; -- 以 | | 代替显示 #
WHEN "1100" => led<="0000000";
WHEN OTHERS => led<="0000000";
END CASE;
END PROCESS p3;
END bhv;
热心网友
时间:2022-06-27 06:43
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity clk_gen is
port(
clk : in std_logic;
clk_scan: out std_logic
);
end clk_gen;
architecture rtl of clk_gen is
signal cnt :integer range 0 to 9; --这里是为了仿真方便,只用了200分频,如果要下载程序,应按实际要求改写数值
begin
process(clk)
begin
if clk'event and clk='1' then
if cnt =cnt'high then --表示cnt的上限值,这样写可以更容易根据实际分频改写
cnt <= 0;
else
cnt <= cnt + 1;
end if;
end if;
end process;
process(cnt,clk)
begin
if clk'event and clk='1' then --200为计数单位,分频
if cnt>=cnt'high/2 then
clk_scan <='1';
else
clk_scan <='0';
end if;
end if;
end process;
end rtl;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity keyboard_ledledled is
port(
clk: in std_logic;
row: out std_logic_vector(3 downto 0);
column: in std_logic_vector(3 downto 0);
rst: in std_logic;
led: out std_logic_vector(3 downto 0)
);
end keyboard_ledledled;
architecture key_input_led of keyboard_ledledled is
component clk_gen
port(
clk : in std_logic;
clk_scan : out std_logic
);
end component;
signal clk_scan: std_logic;
signal key_code: std_logic_vector(3 downto 0);
signal scan_key: std_logic_vector(3 DOWNTO 0);
signal reg: std_logic_vector(7 downto 0);
signal reg1: std_logic_vector(7 downto 0);
signal result: std_logic_vector(7 downto 0);
signal next_state: std_logic_vector(3 downto 0);
signal key_pressed: std_logic;
begin
row<=scan_key;
scaning:clk_gen
port map(clk=>clk,clk_scan=>clk_scan);
PROCESS(clk_scan)
BEGIN
IF(clk_scan'EVENT AND clk_scan = '1')THEN
scan_key<=next_state;
END IF;
END PROCESS;
process(scan_key)
begin
case scan_key is --循环扫描------扫描的时间比检查是否有键按下的时间要快得多
when "0001"=> next_state<= "0010";
when "0010"=> next_state<= "0100";
when "0100"=> next_state<= "1000";
when "1000"=> next_state<= "0001";
when others=> next_state<= "0001";
end case;
end process;
PROCESS(clk_scan)
BEGIN
IF (NOT rst = '1') THEN
key_code <= "0000";
reg1<="00000000";
ELSE
IF(clk_scan'EVENT AND clk_scan='1')THEN
CASE scan_key IS --检查何处有按键按下
WHEN "0001" =>
CASE column IS
WHEN "0001" =>
key_code <= "0001"; -- 1
key_pressed<=not key_pressed;
WHEN "0010" =>
key_code <= "0010"; -- 2
key_pressed<=not key_pressed;
WHEN "0100" =>
key_code <= "0011"; -- 3
key_pressed<=not key_pressed;
WHEN "1000" =>
key_code <= "0100"; -- 4
key_pressed<=not key_pressed;
WHEN OTHERS =>
key_code <= "1111";
END CASE;
WHEN "0010" =>
CASE column IS
WHEN "0001" =>
key_code <= "0101"; -- 5
key_pressed<=not key_pressed;
WHEN "0010" =>
key_code <= "0110"; -- 6
key_pressed<=not key_pressed;
WHEN "0100" =>
key_code <= "0111";
key_pressed<=not key_pressed;
WHEN "1000" =>
key_code <= "1000";
key_pressed<=not key_pressed;
WHEN OTHERS =>
key_code <= "1111";
END CASE;
WHEN "0100" =>
CASE column IS
WHEN "0001" =>
key_code <= "1001";
key_pressed<=not key_pressed;
WHEN "0010" =>
key_code <= "0000";
key_pressed<=not key_pressed;
WHEN "0100" =>
key_code <= "1010";
key_pressed<=not key_pressed;
WHEN "1000" =>
key_code <= "1011";
key_pressed<=not key_pressed;
WHEN OTHERS =>
key_code <= "1111";
END CASE;
WHEN "1000" =>
CASE column IS
WHEN "0001" =>
key_code <= "1100";
key_pressed<=not key_pressed;
WHEN "0010" =>
key_code <= "1101";
key_pressed<=not key_pressed;
WHEN "0100" =>
key_code <= "1110";
key_pressed<=not key_pressed;
WHEN "1000" =>
key_code <= "1111";
key_pressed<=not key_pressed;
WHEN OTHERS =>
key_code <= "1111";
END CASE;
WHEN OTHERS =>
key_code <= "1111";
END CASE;
END IF;
end if;
END PROCESS;
process(key_pressed)
begin
reg<=column&scan_key;
reg1<=reg;
end process;
process(clk_scan)
begin
if clk_scan'event and clk_scan='1' then
result<=reg XOR reg1;
if result= "00000000" then
led<=key_code;
else
led<="0000";
end if;
end if;
end process;
end key_input_led;
vhdl键盘程序,帮忙看一下
以手机键盘为例子写的 LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY keyboard IS PORT( clk:IN STD_LOGIC;keyin:IN STD_LOGIC_VECTOR(2 DOWNTO 0);keyout:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);led:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));END keyboard...
VHDL数字时钟完整程序代码(要求要有元件例化,并且有按键消抖),谢谢啦啦...
end one;仿真波形如下图12:图12 (2)三位二选一:模块图如图13。用以进行正常计时时间与闹铃时间显示的选择,alarm输入为按键。当alarm按键未曾按下时二选一选择器会选择输出显示正常的计时结果,否则当alarm按键按下时选择器将选择输出显示闹铃时间显示。图13 程序如下:library IEEE;use IEEE.STD_...
基于VHDL语言的计算器键盘怎么设置运算清零?
10 我现在要做一个基于VHDL语言的计算器,现在加减乘除模块的有,但是键盘输入模块不会,现在要做的4×4键盘是这样的123+456-789×C0=÷求大神弄一段对应的按键模块,还有就是得保证输... 我现在要做一个基于VHDL语言的计算器,现在加减乘除模块的有,但是键盘输入模块不会,现在要做的4×4键盘是这样的1 2 3 ...
如何利用键盘控制液晶显示器进行简单图形显示?
设计VHDL程序首先要确定程序要实现的功能,最简单的画图功能比如,用上下左右键控制一个光标的移动,然后按另一个键在该光标点处画一个点。程序的输入和输出。输入就是按键上、下、左、右、画点。输出就是液晶屏的显示信号。然后将逻辑功能细分为几个模块(几个process),比如一个模块用来响应按键,...
一个RS232接口的矩阵键盘,需要每个按键按下后发送一个数据,请问怎么改...
一、引言 本方案是用VHDL语言来实现的基于RS232按位串行通信总线的行列式矩阵键盘接口电路,具有复位和串行数据的接收与发送功能,根据发光二极管led0-led2的显示状态可判断芯片的工作情况;实现所有电路功能的程序均是在美国ALTERA公司生产的具有现场可编程功能的芯片EPM7128SLC84-15上调试通过的。能通过动态...
求用vhdl语言编写一个可实现加减乘除、可移位的16位运算器
是用BCD码表示十进制吗?可以每四位分开看。比如BCD码q(11 downto 0)可以表示0到999,前四位是个位,中四位是十位,后四位是百位。不知道对于溢出的有什么要求,我设成溢出后不做任何运算。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity add_sub is port...
用VHDL设计4位数字密码锁
process(Clk1KHz) --扫描键盘 begin if(Clk1KHz'event and Clk1KHz='1') then if(Kr="1111") then kflag1<='0';kcount<=kcount+1;if(kcount=0) then kc<="1110";elsif(kcount=1) then kc<="1101";elsif(kcount=2) then kc<="1011";else kc<="0111";end if;else ...
矩阵键盘的矩阵键盘实验
3. 熟悉掌握 VHDL 语言和 QUARTUS 2 软件的使用。4. 理解状态机的工作原理和设计方法。5. 掌握利用 EDA 工具进行自顶向下的电子系统设计方法。实验任务设计制作一个检测 4*4 矩阵键盘的按键编码的实验, 把实际按键的 键值的八位编码先转换成从 0000—1111 的编码,再译成数码管能识别 的八位...
vhdl中如何调用另外一个文件里的process
描述: Windows信使服务调用Windows驱动和程序管理在启动。 介绍:msgsrv32.exe 一个管理信息窗口的应用程序,win9x下如果声卡或者显卡驱动程序配置不正确,会导致死机或者提示msgsrv32.exe 出错。 (15)[mstask.exe] 进程文件: mstask or mstask.exe 进程名称: Windows计划任务 描述: Windows计划任务用于设定继承在...
电子硬件工程师要求?
最好能熟悉MCS-51,写程序不是问题,重要的是思路,但一定要做出来。 3、PCB。基本要求是4层板,要了解PCB对EMI、ESD的影响并想办法避免。PCB能做得既美观又没有问题是需要花时间来训练的。 4、VHDL。在国外这是要求掌握基本技能,在国内也正在普及。主要是用来开发FPGA/CPLD器件和逻辑仿真,还有IC设计也常用VHDL作...