课程设计报告-基于vhdl的电子密码锁设计内容摘要:

elsif(sel(2)=39。 039。 )then szkzj=39。 039。 gnkzj=39。 139。 elsif(sel(3)=39。 039。 ) then szkzj=39。 039。 gnkzj=39。 139。 end if。 elsif(R(3)=39。 039。 ) then 第 三 章 硬件原理及软件设计 10 if(sel(0)=39。 039。 )then querenj1=39。 139。 szkzj=39。 039。 gnkzj=39。 139。 else querenj1=39。 039。 end if。 if(sel(1)=39。 039。 ) then sanchuj1=39。 139。 szkzj=39。 039。 gnkzj=39。 139。 else sanchuj1=39。 039。 end if。 if(sel(2)=39。 039。 )then gaimij1=39。 139。 szkzj=39。 039。 gnkzj=39。 139。 else gaimij1=39。 039。 end if。 if(sel(3)=39。 039。 ) then rest1=39。 139。 szkzj=39。 039。 gnkzj=39。 139。 else rest1=39。 039。 end if。 end if。 end if。 end process p4。 p8:process(szkzj,gnkzj) begin if szkzj=39。 139。 and gnkzj=39。 039。 then dataout=temp。 else dataout=null。 end if。 if gnkzj=39。 139。 and szkzj=39。 039。 then querenj=querenj1。 sanchuj=sanchuj1。 gaimij=gaimij1。 rest=rest1。 else querenj=null。 sanchuj=null。 gaimij=null。 rest=null。 end if。 end process p8。 szkzj1=szkzj。 gnkzj1=gnkzj。 第 三 章 硬件原理及软件设计 11 END arth。 键盘消抖电路 因为按键大多是机械式开关 , 在开关切换的瞬间会在接解点出现来回弹跳的现象 , 虽然只是按了一次键 , 实际产生的按键信号却不只跳动一次 , 经过取样信号的检查后 , 将会造成误码判断 , 认为是按了两次键。 消除按键抖动可以用硬件电路来实现,例如,利用 R— S 触发器来锁定按键状态,消除抖动的影响。 也可以利用现成的专用消抖电路,如 MC14490 就是六路消抖电路。 较为简单的方法是用软件延时方法来消除按键的抖动,也就是说,一旦发现有按键按下,就延时 20ms 以后在测按键的状态。 这样就避免开按键发生抖动的那一段时间,使 CPU 能可靠地读按键状态。 在编制键盘扫描程序时,只要发现按键状态有变化,即无论是按下还是松开,程序都应延时 20ms 以后再进行其他操作。 如果调整取样频率 , 弹跳现象可得到改善。 本论文 应用 D 触发器可以实现消抖作用。 原理图如图 34VHDL 语言键盘消抖电路原理图所示: 图 34 键盘消抖电路原理图 键盘消抖电路的程序代码: library ieee。 use。 entity d4 is port is( clk:in std_logic。 a: in std_logic_vector(3 downto 0)。 rest1,querenj1,gaimij1,sanchuj1:in std_logic。 第 三 章 硬件原理及软件设计 12 q:out std_logic_vector(3 downto 0)。 rest2,querenj2,gaimij2,sanchuj2:out std_logic)。 end d4。 architecture f of d4 is signal qi:integer range 0 to 3。 signal clk_temp:std_logic。 begin process(clk) begin if rising_edge(clk) then if qi=3 then qi=0。 clk_temp=not clk_temp。 else qi=qi+1。 end if。 end if。 end process。 process(clk_temp) begin if clk_temp 39。 event and clk_temp =39。 139。 then q =a。 rest2=rest1。 querenj2=querenj1。 gaimij2=gaimij1。 sanchuj2=sanchuj1。 end if。 end process。 end f。 移位寄存电路 表 31 移位寄存器功能表 输入数据 输出数据 第 三 章 硬件原理及软件设计 13 第一次 0000 0000 第二次 0001 00000001 第三次 0010 000000010010 第四次 0011 0000000100100011 第五次 0100 0001001000110100 由于按键按下时,键盘输入的是 4 位二进制数,每次输入后都会前一次输入的都会消失,所以必须对键盘输出进行移位储存才能得要 16 位二进制数即 4 位十进制数。 移位寄存工作原理就是在下一次数据输入前,对其进行移位寄存以确保不会丢失,如我们定义输入为 4 位二进制数,输出为 16 为二进制数,由低位向高位移位,第一次输入的是 0000,第二次输入的是 0001,第三次输入的是 0010,第四次是 0011,这时输出的就是 0000000100100011。 如表 31 当用户发现输入密码错误时可以进行 删除,这里删除采用了移位操作,按一次删除键输出数据就向低位移动已达到删除功能。 原理图如图 35 VHDL 语言 移位寄存电路 原理图所示: 图 35 移位寄存电路 移位寄存电路程序代码: library ieee。 use。 entity yw is port(input:in std_logic_vector(3 downto 0)。 rest,shanchu,clk :in std_logic。 output :out std_logic_vector(15 downto 0))。 第 三 章 硬件原理及软件设计 14 end yw。 architecture behave of yw is signal output_temp: std_logic_vector(15 downto 0)。 signal output_temp(3 downto 0): std_logic_vector(3 downto 0)。 begin process(clk) begin if rest=39。 139。 then output=null。 elsif (rising_edge(clk)) then if shanchu=39。 039。 then output_temp(15 downto 12)=output_temp(11 downto 8)。 output_temp(11 downto 8)=output_temp(7 downto 4)。 output_temp(7 downto 4)=output_temp(3 downto 0)。 output_temp(3 downto 0)=input。 else output_temp(。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。