vhdl键盘依次输入数字如何实现

vhdl键盘依次输入数字如何实现,第1张

键盘输入的的确是四位二进制编码没错,你可以在百度里搜索“FPGA键盘输入”,出来的第一个博客讲的就是这个内容。数码管左移很简单,每次判断完有按键按下之后,开始进行动态扫描,比如从1到3无限循环,1的时候显示个位数,2的时候显示十位数,具体程序如下

process(clk2)--数码管动态显示的程序

variable countx: integer range 0 to1024 :=0--计数值,用于添加闪烁

variable count0: integer range 0 to10 :=0--数码管显示个位数

variable count1: integer range 0 to10 :=0--数码管显示十位数

variable play: integer range 0 to 9:=0

variable countplay: integer range 0to 50 :=0

variable countplay1: integer range 0to 3 :=0

variable flash:integer range 0 to15:=0

begin

if(clk2' event and clk2= '1') then

countx := countx + 1

countplay := countplay + 1

if(countx = 1024) then

countx := 0

end if

if (T>=50) then --判断十位数的大小

count1:=5

elsif (T>=40) then

count1:=4

elsif (T>=30) then

count1:=3

elsif (T>=20) then

count1:=2

elsif (T>=10) then

count1:=1

else

count1:=0

end if

count0:=T-10*count1

if(countplay = 5) then

countplay := 0

countplay1 := countplay1 + 1

if(countplay1 = 3) then

countplay1 := 0

end if

end if

if (stop='1'and countx<=200 )then --闪烁信号所加的位置

wx<="11111111"

else

if(countplay1 = 0) then wx <="11111110"play:= count0--位选信号

end if

if (countplay1 = 1) then wx <="11111101"play:= count1

end if

end if

case play is--数码管段选信号

when 0 =>dx <="11000000"

when 1 =>dx <="11111001"

when 2 =>dx <="10100100"

when 3 =>dx <="10110000"

when 4 =>dx <= "10011001"

when 5 =>dx<="10010010"

when 6 =>dx <="10000010"

when 7 =>dx <="11111000"

when 8 =>dx <="10000000"

when 9 =>dx <="10010000"

--when others =>Y <="00000000"

end case

end if

end process

(这个程序里面一个闪烁的信号,你没用的话可以直接去掉,不影响其他部分)

library ieee

use ieee.std_logic_1164.all

use ieee.std_logic_unsigned.all

entity yima is

port(kin3,kin2,kin1,kin0,clk:in std_logic

sel2,sel1,sel0:in std_logic

q:out std_logic_vector(6 downto 0))

end yima

architecture a of yima is

signal a:std_logic_vector(3 downto 0)

signal b:std_logic_vector(2 downto 0)

signal p:std_logic_vector(6 downto 0)

signal m:std_logic_vector(6 downto 0)

begin

process(clk)

begin

if clk'event and clk='1'then

a<=kin3&kin2&kin1&kin0

b<=sel2&sel1&sel0

m<=b&a

case m is

when "0001110" =>p<="1111110"-----0 键显示 0

when "0011110" =>p<="0110000"-----1 键显示 1

when "0101110" =>p<="1101101"-----2 键显示 2

when "0111110" =>p<="1111001"-----3 键显示 3

when "1101110" =>p<="0110011"-----4 键显示 4

when "1111110" =>p<="1011011"-----5 键显示 5

when "0001101" =>p<="1011111"-----6 键显示 6

when "0011101" =>p<="1110000"-----7 键显示 7

when "1001101" =>p<="1111110"-----8 键显示 0

when "1011101" =>p<="0110000"-----9 键显示 1

when "1101101" =>p<="1101101"-----A 键显示 2

when "1111101" =>p<="1111001"-----B 键显示 3

when "0101011" =>p<="0110011"-----C 键显示 4

when "0111011" =>p<="1011011"-----D 键显示 5

when "1001011" =>p<="1011111"-----E 键显示 6

when "1011011" =>p<="1110000"-----F 键显示 7

when "0000111" =>p<="0000000"

when others =>p<=p

end case

end if

q<=p

end process

end a


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11599743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存