基于VHDL的电子密码锁.docx

上传人:b****6 文档编号:5834216 上传时间:2023-01-01 格式:DOCX 页数:16 大小:351.66KB
下载 相关 举报
基于VHDL的电子密码锁.docx_第1页
第1页 / 共16页
基于VHDL的电子密码锁.docx_第2页
第2页 / 共16页
基于VHDL的电子密码锁.docx_第3页
第3页 / 共16页
基于VHDL的电子密码锁.docx_第4页
第4页 / 共16页
基于VHDL的电子密码锁.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

基于VHDL的电子密码锁.docx

《基于VHDL的电子密码锁.docx》由会员分享,可在线阅读,更多相关《基于VHDL的电子密码锁.docx(16页珍藏版)》请在冰豆网上搜索。

基于VHDL的电子密码锁.docx

基于VHDL的电子密码锁

 

华南师大学

课程设计实验报告

 

课程名称:

可编程数字系统设计

课程设计题目:

电子密码锁

XX:

程硕

学院:

物理与电信工程学院

专业:

理综一班

年级:

2011

学号:

一、设计原理

用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所示

图1

Xiao_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.控制电路源程序

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitymainis

port(key1,key2,key3,key4,key5:

instd_logic;

clk:

instd_logic;

num_shuma:

outstd_logic_vector(3downto0);

set_shuma:

outstd_logic_vector(3downto0);

led:

outstd_logic:

='0';

sel:

outstd_logic);

endentitymain;

architecturelockofmainis

signaltemp_1,temp_led,temp_shuma,reset_all,reset_mima

temp_reset,key1_clear,key2_clear,key3_clear,key4_clear:

std_logic;

signalbit_one_in:

integerrange0to9:

=1;--insideofnumber

signalbit_two_in:

integerrange0to9:

=2;

signalbit_three_in:

integerrange0to9:

=3;

signalbit_four_in:

integerrange0to9:

=4;

signalshow_shuma_location:

std_logic_vector(1downto0);--locationofshuma

signalbit_one_out,bit_two_out,bit_three_out,bit_four_out:

integerrange0to9;--outsideofnumber

signallocation:

std_logic_vector(1downto0);--insidelocationofnumber

signalnumber_led:

integerrange0to5000000;

signalnumber_shuma:

integerrange0to50000;

signalnumber_error:

integerrange0to3;

signaltwice:

integerrange0to2;

signalclear_num:

integerrange0to3;

begin

show_location_set:

process(temp_shuma)--thelocationofshuma_guan

begin

if(temp_shuma'eventandtemp_shuma='1')then

show_shuma_location<=show_shuma_location+1;

endif;

endprocess;

show_shuma:

process(clk)--thenumberofshuma_guan

begin

caseshow_shuma_locationis

when"00"=>

num_shuma<=conv_std_logic_vector(bit_one_out,4);

set_shuma<="1110";

when"01"=>

num_shuma<=conv_std_logic_vector(bit_two_out,4);

set_shuma<="1101";

when"10"=>

num_shuma<=conv_std_logic_vector(bit_three_out,4);

set_shuma<="1011";

when"11"=>

num_shuma<=conv_std_logic_vector(bit_four_out,4);

set_shuma<="0111";

endcase;

if(reset_all='1')then

num_shuma<="0000";--xianshizhi0

endif;

endprocess;

shuma_200:

process(clk)--usetodelaylocationset

begin

if(clk'eventandclk='1')then

if(number_shuma=50000)then

number_shuma<=0;

temp_shuma<=nottemp_shuma;

elsenumber_shuma<=number_shuma+1;

endif;

endif;

endprocessshuma_200;

 

add_outside:

process(clk,reset_all)--key1addnum

begin

if(key1'eventandkey1='0')then

key1_clear<='1';

caselocationis

when"00"=>bit_one_out<=bit_one_out+1;

if(bit_one_out=9)thenbit_one_out<=0;

endif;

when"01"=>bit_two_out<=bit_two_out+1;

if(bit_two_out=9)thenbit_two_out<=0;

endif;

when"10"=>bit_three_out<=bit_three_out+1;

if(bit_three_out=9)thenbit_three_out<=0;

endif;

when"11"=>bit_four_out<=bit_four_out+1;

if(bit_four_out=9)thenbit_four_out<=0;

endif;

endcase;

endif;

if(clear_num=0)thenkey1_clear<='0';

endif;

if(reset_all='1')then

bit_one_out<=0;

bit_two_out<=0;

bit_three_out<=0;

bit_four_out<=0;

endif;

endprocessadd_outside;

location_set:

process(clk,reset_all)--key2location_set

begin

if(key2'eventandkey2='0')then

--led<='0';

key2_clear<='1';

location<=location+1;

endif;

if(reset_all='1')then

location<="00";

endif;

if(clear_num=0)thenkey2_clear<='0';

endif;

endprocess;

set_mima:

process(clk,clear_num)--key4setmima

begin

if(twice=2)then

if(key4'eventandkey4='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;

endif;

endif;

if(clear_num=0)thenkey4_clear<='0';

endif;

if(clear_num=3)then

bit_one_in<=1;

bit_two_in<=2;

bit_three_in<=3;

bit_four_in<=4;

endif;

endprocess;

reset:

process(clk,temp_reset,key1_clear,key2_clear,key3_clear,key4_clear)--key5clearandreset

begin

if(key5'eventandkey5='0')then

--led<='0';

reset_all<='1';

if(clear_num=3)then

clear_num<=0;

elseclear_num<=clear_num+1;

endif;

endif;

if(location="00"andbit_one_out=0andbit_two_out=0andbit_three_out=0andbit_four_out=0)then

reset_all<='0';

endif;

if(temp_reset='1')then

reset_all<='1';

endif;

if(key1_clear='1'orkey2_clear='1'orkey3_clear='1'orkey4_clear='1')then--ifotherkeyclearnum

clear_num<=0;

endif;

endprocess;

pare:

process(clk,reset_all)--key3pare

begin

if(key3'eventandkey3='0')then

key3_clear<='1';

if(bit_one_in=bit_one_outandbit_two_in=bit_two_outand

bit_three_in=bit_three_outandbit_four_in=bit_four_out)then

led<='1';

temp_1<='0';

temp_reset<='1';

number_error<=0;

if(twice=2)then

twice<=twice;

else

twice<=twice+1;

endif;

else

twice<=0;

if(number_error=3)then

number_error<=1;

temp_1<='1';

else

number_error<=number_error+1;

led<='0';

temp_1<='0';

endif;

endif;

endif;

if(clear_num=0)thenkey3_clear<='0';

endif;

if(location="00"andbit_one_out=0andbit_two_out=0andbit_three_out=0andbit_four_out=0)then--cleartongxin

temp_reset<='0';

endif;

if(temp_1='1')then

led<=temp_led;

endif;

endprocesspare;

one_second:

process(clk)

begin

if(clk'eventandclk='1')then

if(number_led=5000000)then

number_led<=0;

temp_led<=nottemp_led;

elsenumber_led<=number_led+1;

endif;

endif;

endprocessone_second;

 

endarchitecturelock;

 

2.消抖源程序

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityxiao_douis

port(clk:

instd_logic;

din:

instd_logic;

dout:

outstd_logic);

endentityxiao_dou;

architectureaofxiao_douis

signalnum:

integerrange0to1000000;

signaltemp_10,temp,temp1:

std_logic;

begin

process(clk)

begin

if(clk'eventandclk='1')then

if(din='0')then

if(num=1000000)thennum<=num;

elsenum<=num+1;

endif;

if(num=999999)thendout<='1';

elsedout<='0';

endif;

elsenum<=0;

endif;

endif;

endprocess;

endarchitecturea;

3.译码源程序

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityyimais

port(yuanma:

instd_logic_vector(3downto0);

shuma:

outstd_logic_vector(7downto0));

endentityyima;

architectureaofyimais

begin

process(yuanma)is

begin

caseyuanmais

when"0000"=>shuma<="00000011";

when"0001"=>shuma<="10011111";

when"0010"=>shuma<="00100101";

when"0011"=>shuma<="00001101";

when"0100"=>shuma<="10011001";

when"0101"=>shuma<="01001001";

when"0110"=>shuma<="01000001";

when"0111"=>shuma<="00011111";

when"1000"=>shuma<="00000001";

when"1001"=>shuma<="00011001";

whenothers=>shuma<="00000001";

endcase;

endprocess;

endarchitecturea;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1