基于VHDL的电子密码锁.docx_第1页
基于VHDL的电子密码锁.docx_第2页
基于VHDL的电子密码锁.docx_第3页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程硕基于VHDL的电子密码锁设计 14 / 14华南师范大学课程设计实验报告课程名称:可编程数字系统设计课程设计题目:电子密码锁姓 名:程硕学院:物理与电信工程学院专 业:理综一班年 级:2011学 号:20112600104一、设计原理用VHDL设计电子密码锁方案:作为通用电子密码锁,主要由 3 个部分组成:数字密码按键输入电路、密码锁控制电路和密码锁显示电路,作为电子密码锁的输入电路。可供选择的方案有数字机械式键盘和触摸式数字键盘等多种。(1)密码锁输入电路包括时序产生电路、键盘检测电路、键盘消抖电路等几个小的功能电路。(2)密码锁控制电路包括按键数据存储电路,恢复出厂密码、两次正确输入后可修改密码、密码核对,多次错误报警,清屏等几个小的功能电路。(3)八段数码管显示电路主要将待显示数据的BCD码转换成数码器的八段显示驱动编码。二、系统分析本次课程设计成功地设计了一个简单的数字电子密码锁,密码为 4 位。将电子密码锁分为以下几个模块:按键消抖模块、密码锁逻辑控制模块和密码锁显示模块,实现了以下功能: (1)密码输入:KEY1按下一次,数码管上显示数字加一,相应位置输入密码加一(2)位置选择:KEY2按下一次,数码管选择位左移一位(3)密码确认:KEY3按下一次,比较外部输入密码与原密码,正确LED长亮,错误LED变暗,同时显示密码置0; (4)密码修改:正确输入两次密码后,按下KEY4一次,将当前输入设为新的密码; (5)清屏:KEY5按下一次,外部输入置0;(6)恢复出厂设置:连续按下KEY5三次后恢复出厂密码“1234”;三、程序设计1 由于程序稍显庞大,故采取分层次设计的方法,顶层采用画图法设计,底层采用VHDL语言进行设计。顶层电路图如图1所示图1Xiao_dou模块为按键消抖模块,main为密码锁控制模块,yima为数码管显示译码模块。Set_shuma端口为数码管段选端口,用于选择数码管。Led端口为led灯端口,key1,key2,key3,key4,key5为五个按键接口,show_shuma端口为数码管位选选择端口。2 底层设计a) 由于按键为机械按键,故按下一次会产生多次脉冲,当产生第一次下降沿的时候延时一段时间后,再继续检测是否有下降沿产生。主体程序如下:b) 数码管译码显示进程:将0至9的4位矢量型数字转化为相应8位数码管显示数字c) 电子密码锁控制电路:i. 数码管位置选择进程:当数码管位置选择时钟到来时,数码管显示位左移一位,利用人眼的视觉余辉效果,产生4位数码管同时点亮的效果。ii. 数码管位置选择时钟信号发生进程:将系统时钟分频,产生500HZ占空比为1:1的方波,用于控制数码管位置选择。iii. 整型密码转化为矢量型密码,位选选择进程:利用CASE语句将不同位置的密码值显示在相应的数码管上。iv. 外部输入密码变更进程:当KEY1按下时外部输入密码加1,并在数码管上显示出来,数字从1至9循环;后半部分为当清屏信号到来时,外部输入密码置0。v. 按键位置选择进程:KEY2按下时数码管位置选择端左移一位,后半部分为当清屏信号到来时,位置置0。vi. 密码设置,重置进程:当密码连续正确两次后,按下KEY4键,将现在显示的密码置为新密码。后半部分为恢复出厂设置密码。vii. 清屏,恢复出厂设置进程:当KEY5按下时产生清屏信号,当KEY5连续按下三次后产生恢复出厂设置信号。后半部分为清屏与恢复出厂设置信号的清除程序,用于清除产生的清屏与恢复出厂设置信号。viii. 密码比较进程:比较当前输入密码与内部密码的值,如相同则LED长亮,如不同则LED暗,如连续3次输入错误密码则LED闪烁报警。ix. LED闪烁脉冲发生进程:用于产生LED闪烁所需方波脉冲四、仿真/实验结果1. 密码正确:2. 密码错误:3. 清屏:五、结论或分析各项实验结果均成功,能够很好的实现,密码比较,设置密码,清屏,恢复出厂设置等各项功能。六、使用说明1. S5:KEY1按下后外部输入密码加1;2. S4:KEY2按下后输入选择位置左移一位;3. S3:KEY3按下后比较输入密码与内部密码;4. S4:KEY4连续输入两次正确密码后按下,将当前显示密码设为新密码;5. S5:KEY5按下一次清屏,连续按下三次后恢复出厂设置。七、源程序1. 控制电路源程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity main is port(key1,key2,key3,key4,key5 :in std_logic; clk :in std_logic; num_shuma :out std_logic_vector(3 downto 0); set_shuma : out std_logic_vector(3 downto 0); led :out std_logic:=0; sel :out std_logic);end entity main;architecture lock of main issignal temp_1,temp_led, temp_shuma,reset_all,reset_mima ,temp_reset,key1_clear,key2_clear,key3_clear,key4_clear: std_logic;signal bit_one_in :integer range 0 to 9:=1;-inside of numbersignal bit_two_in :integer range 0 to 9:=2;signal bit_three_in :integer range 0 to 9:=3;signal bit_four_in :integer range 0 to 9:=4;signal show_shuma_location:std_logic_vector(1 downto 0);-location of shumasignal bit_one_out,bit_two_out,bit_three_out,bit_four_out :integer range 0 to 9; -outside of numbersignal location :std_logic_vector(1 downto 0);-inside location of numbersignal number_led :integer range 0 to 5000000;signal number_shuma :integer range 0 to 50000;signal number_error :integer range 0 to 3;signal twice :integer range 0 to 2;signal clear_num:integer range 0 to 3;begin show_location_set:process(temp_shuma)-the location of shuma_guanbeginif(temp_shumaevent and temp_shuma=1)thenshow_shuma_locationnum_shuma=conv_std_logic_vector(bit_one_out,4);set_shumanum_shuma=conv_std_logic_vector(bit_two_out,4);set_shumanum_shuma=conv_std_logic_vector(bit_three_out,4);set_shumanum_shuma=conv_std_logic_vector(bit_four_out,4);set_shuma=0111;end case;if(reset_all=1)thennum_shuma=0000;-xian shi zhi 0end if;end process;shuma_200:process(clk)-use to delay location setbeginif(clkevent and clk=1)thenif(number_shuma=50000)thennumber_shuma=0;temp_shuma=not temp_shuma;else number_shuma=number_shuma+1;end if;end if;end process shuma_200;add_outside:process(clk,reset_all)-key1 add numbeginif(key1event and key1=0)thenkey1_clearbit_one_out=bit_one_out+1;if(bit_one_out=9)then bit_one_outbit_two_out=bit_two_out+1;if(bit_two_out=9)then bit_two_outbit_three_out=bit_three_out+1;if(bit_three_out=9)then bit_three_outbit_four_out=bit_four_out+1;if(bit_four_out=9)then bit_four_out=0;end if;end case;end if;if(clear_num=0)thenkey1_clear=0;end if;if(reset_all=1)thenbit_one_out=0;bit_two_out=0;bit_three_out=0;bit_four_out=0;end if;end process add_outside;location_set:process(clk,reset_all)-key2 location_setbegin if(key2event and key2=0)then-led=0;key2_clear=1;location=location+1;end if;if(reset_all=1)thenlocation=00;end if;if(clear_num=0)thenkey2_clear=0;end if;end process;set_mima:process(clk,clear_num)-key4 set mimabeginif(twice=2)thenif(key4event and key4=0)then-led=0;key4_clear=1;bit_one_in=bit_one_out;bit_two_in=bit_two_out;bit_three_in=bit_three_out;bit_four_in=bit_four_out;end if;end if;if(clear_num=0)thenkey4_clear=0;end if;if(clear_num=3)thenbit_one_in=1;bit_two_in=2;bit_three_in=3;bit_four_in=4;end if;end process;reset:process(clk,temp_reset,key1_clear,key2_clear,key3_clear,key4_clear)-key5 clear and resetbeginif(key5event and key5=0)then-led=0;reset_all=1;if(clear_num=3)thenclear_num=0;else clear_num=clear_num+1;end if;end if;if(location=00 and bit_one_out=0 and bit_two_out=0 and bit_three_out=0 and bit_four_out=0)thenreset_all=0;end if;if(temp_reset=1)thenreset_all=1;end if;if(key1_clear=1 or key2_clear=1 or key3_clear=1 or key4_clear=1)then-if other key clear numclear_num=0;end if;end process;compare:process(clk,reset_all)-key3 comparebeginif(key3event and key3=0)thenkey3_clear=1;if(bit_one_in=bit_one_out and bit_two_in=bit_two_out and bit_three_in=bit_three_out and bit_four_in=bit_four_out)thenled=1;temp_1=0;temp_reset=1;number_error=0;if(twice=2)thentwice=twice;elsetwice=twice+1;end if;else twice=0;if(number_error=3)thennumber_error=1;temp_1=1;else number_error=number_error+1;led=0;temp_1=0;end if;end if;end if;if(clear_num=0)thenkey3_clear=0;end if;if(location=00 and bit_one_out=0 and bit_two_out=0 and bit_three_out=0 and bit_four_out=0)then-clear tong xintemp_reset=0;end if;if(temp_1=1)thenled=temp_led;end if;end process compare ;one_second:process(clk)beginif(clkevent and clk=1)thenif(number_led=5000000)thennumber_led=0;temp_led=no

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论