资源描述
概述
在当今社会中,大家对于隐私保护和对物品安全重视程度和日俱增。所以,使用了现代电子技术电子密码锁便有了广泛应用前景。此次所设计电子密码锁,能够实现该六位十进制并行密码保护,当输入密码和锁内密码一致时,绿灯亮,开锁;当输入密码和锁内密码不一致时,红灯亮,不能开锁。密码锁密码可由用户自行设置,并可在液晶显示器上显示所输入密码。为大家财产、信息安全提供了可靠地保障。
此次设计基于VHDL语言,对并行六位电子密码锁进行设计,并对设计过程进行了具体描述。采取VHDL语言进行电子密码锁设计可使设计工作简练直观,快速实现既定功效。电子密码锁在对财产安全保护等方面全部有着关键作用,应用前景很广泛。开锁代码为六位十进制数,当输入代码位数和位值和锁内给定密码一致,且按要求程序开锁时,方可开锁,并点亮开锁指示灯。不然,系统进入“错误”状态,并发出报警信号。开锁程序由设计者确定,并要求锁内给定密码是可调,且预置方便,保密性好。并行数字锁报警方法是点亮指示灯,并使喇叭鸣叫来报警,直到按下复位开关,报警才停止。此时,数字锁又自动进入等候下一次开锁状态。
一、 设计关键内容
1、 密码锁串行输入几位十进制数字口令
2、 输入口令全部正确即开锁并有绿灯显示
3、 口令输入最大次数3次,要求在完全输入六位以后进行判定口令正确是否;输入3次以后还不能开锁,进入死锁状态并报警
4、 有对应显示功效
5、 开锁后能再次上锁
二、系统设计方案
作为通用电子密码锁,关键由三个部分组成:数字密码输入电路、密码锁控制电路和密码锁显示电路。
(1)密码锁输入电路包含时序产生电路、键盘扫描电路、键盘译码电路等多个小功效电路。
(2) 密码锁控制电路包含按键数据缓冲存放电路,密码清除、存放、激活电锁电路(寄存器清除信号发生电路),密码查对(数值比较电路),解锁电路(开/关门锁电路)等多个小功效电路。
(3)密码显示电路关键是在液晶显示器显示输入数值。
2.1密码锁输入电路设计
是电子密码锁输入电路框图,由键盘扫描电路、弹跳消除电路、键盘译码电路、按键数据缓存器,加上外接一个4×4矩阵式键盘组成。
7
9
8
按键数据
键盘输入
4
6
5
工作时钟脉冲信号
键盘扫描信号
弹跳消除电路
键盘译码电路
按键数据缓存器
0
3
2
1
键盘扫描电路
图1-1 密码锁输入电路框图
1.矩阵式键盘工作原理
KC1
KC2
矩阵式键盘是一个常见输入装置,在日常生活中,矩阵式键盘在计算机、电话、手机、微波炉等各式电子产品上已经被广泛应用。图1-2是一个3×4矩阵式键盘面板配置图,其中数字0~9作为密码数字输入按键。
KC0
KR0(11)
KR1(10)
KR2(01)
KR3(00)
0111
1011
1101
1110
3
0
2
1
6
5
4
7
9
8
图1-2 4 ×4矩阵式键盘面板配置
2.2密码锁输入电路各关键功效模块设计
1) 时序产生电路
本时序产生电路中使用了三种不一样频率工作脉冲波形:系统时钟脉冲(它是系统内部全部时钟脉冲源头,且其频率最高)、弹跳消除取样信号、键盘扫描信号。
2) 键盘扫描电路
扫描电路作用是用来提供键盘扫描信号,扫描信号改变次序依次为1110-1101-1011-0111-1110......依序地周而复始。
3) 弹跳消除电路
因为本设计中采取矩阵式键盘是机械开关结构,所以在开关切换瞬间会在接触点出现信号往返弹跳现象,对于电子密码锁这种灵敏度较高电路这种弹跳将很可能会造成误动作输入,从而影响到密码锁操作正确性。
从图1-3中能够观察出弹跳现象产生原因,即使只是按下按键一次然后放掉,然而实际产生按键信号却不止跳动一次,经过取样信号检验后,将会造成误判定,认为键盘按了两次。假如调整抽样频率(图4.5所表示),能够发觉弹跳现象取得了改善。
图1-3弹跳现象产生错误抽样结果
图1-4 调整抽样频率后得到抽样结果
4) 键盘译码电路
上述键盘中按键可分为数字按键和文字按键,每一个按键可能负责不一样功效,比如清除数码、退位、激活电锁、开锁等。
5) 按键存放电路
因为每次扫描会产生新按键数据,可能会覆盖前面数据,所以需要一个按键存放电路,将整个键盘扫描完成后结果统计下来。按键存放电路能够使用移位寄存器组成。
图1-5 输入电路仿真波形图
2.3 密码锁控制电路设计
密码锁控制电路是整个电路控制中心,关键完成对数字按键输入和功效按键输入响应控制。
1.数字按键输入响应控制
(1) 假如按下数字键,第一个数字会从显示器最右端开始显示,以后每新按一个数字时,显示器上数字必需左移一格,方便将新数字显示出来。
(2) 假如要更改输入数字,能够按倒退按键来清除前一个输入数字,或按清除键清除全部输入数字,再重新输入六位数。
(3) 因为这里设计是一个六位电子密码锁,所以当输入数字键超出四个时,电路不予理会,而且不再显示第六个以后数字。
2.4功效按键输入响应控制
(1) 清除键:清除全部输入数字,即做归零动作。
(2) 激活电锁键:按下此键时可将密码锁门上锁。(上锁前必需预先设定一个六位数字密码。)
(3) 解除电锁键:按下此键会检验输入密码是否正确,若密码正确无误则开门。
输入文字模式
开始输入六位数字,在输入过程中可能用到删除键
上锁工作模式
密码锁激活上锁
开锁工作模式
检验输入密码是否有效
查对输入密码是否有效
全部正确后解除电锁
图1-5 电子密码锁三种模式及关系
2.5 密码锁显示电路设计
密码锁显示电路设计比较复杂,这里直接采取12864液晶屏进行显示。
2.6 密码锁整体组装设计
将前面各个设计好功效模块进行整合,可得到一个完整电子密码锁系统整体组装设计原理图,图1-6所表示。
图1-6 密码锁整体组装设计原理图
三、 系统扩展思绪
(1) 本系统基础达成作为数字密码锁绝大部分功效,但还有很多不足或需完善地方。比如说采取4×4通用机械键盘受到键盘数量限制,在很大程度上限制了其功效扩展。
(2) 设计外围电路:系统用方波信号源,直流工作电源。
(3) 可要求设计制作整个系统,包含PCB制作。
四、 试验收获
课程设计是培养学生综合利用所学知识,发觉,提出,分析和处理实际问题,锻炼实践能力关键步骤,是对学生实际工作能力具体训练和考察过程。伴随科学技术发展日新月异,FPGA已经成为当今计算机应用中空前活跃领域,在生活中能够说无处不在。所以作为二十一世纪大学来说掌握eda开发技术是十分必需。
回顾此次课程设计,我感慨颇多,确实,从理论到实践,在很长一段时间里,能够说是苦多于甜,但确实学到了很多东西,不仅能够巩固以前学到知识,还学到很多没学过知识。经过此次课程设计,使我了解了理论和实际结合关键性,只有理论知识是远远不够。在设计过程中,发觉自己以前学习知识了解不够深刻,掌握不够牢靠等等。经过这次课设以后,一定要把以前学习知识温故知新。
这次课设最终完成,经过老师细心讲解,我处理了很多问题。在这里,感谢老师细心指导。同时对于帮助我同学,也表示衷心感谢。
附录
1、 液晶显示程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use IEEE.STD_LOGIC_ARITH.ALL;
entity clock_lcd_disp is
generic(divide_to_100k:integer:=500);
port(clk:in std_logic;
DATAIN:in std_logic_vector(31 downto 0);
din: in INTEGER RANGE 15 DOWNTO 0;
rw,rs,e,lcd_rst:out std_logic;
lcd_data:out std_logic_vector(7 downto 0));
end clock_lcd_disp;
architecture tcl of clock_lcd_disp is
signal mima:std_logic_vector(31 downto 0):="01111000";
signal clk_100k:std_logic;
signal clkout:std_logic;
signal temp:std_logic_vector(7 downto 0);
type state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,s31);
signal current_s:state;
type data_buffer is array(0 to 15)of std_logic_vector(7 downto 0);
type data_buffer1 is array(0 to 7)of std_logic_vector(7 downto 0);
signal time:std_logic_vector(23 downto 0);
signal disp_time:data_buffer1:=(
x"31",x"32",x"3a",x"33",
x"34",x"3a",x"35",x"36");
constant data_buf0:data_buffer:=(x"20",x"20",x"bb",x"aa", --华科武昌分校 80
x"bf",x"c6",x"ce",x"e4",
x"b2",x"fd", x"b7",x"d6",
x"d0",x"a3",x"20",x"20");
constant data_buf1:data_buffer:=(x"20",x"20",x"b5",x"e7", --电子密码锁 90
x"d7",x"d3",x"c3",x"dc",
x"c2",x"eb",x"cb",x"f8",
x"20",x"20",x"20",x"20");
constant data_buf2:data_buffer:=(x"20",x"20",x"c7",x"eb",
x"ca",x"e4",x"c8",x"eb", --请输入密码: 88
x"c3",x"dc",x"c2",x"eb",
x"3a",x"20",x"20",x"20");
constant data_buf3:data_buffer:=(x"20",x"20",x"d6",x"d8",
x"d0",x"c2",x"ca",x"e4", --重新输入
x"c8",x"eb",x"20",x"20",
x"20",x"20",x"20",x"20");
constant data_buf4:data_buffer:=(x"20",x"20",x"bd",x"e2", x"cb",x"f8",x"b3",x"c9", --解锁成功
x"b9",x"a6",x"20",x"20",
x"20",x"20",x"20",x"20");
constant data_buf5:data_buffer:=( x"20",x"20", --进入死锁状态
x"bd",x"f8",x"c8",x"eb",
x"cb",x"c0",x"cb",x"f8",
x"d7",x"b4",x"cc",x"ac",
x"20",x"20");
constant data_buf6:data_buffer:=(x"20",x"20",x"bd",x"e2", --
x"cb",x"f8",x"b3",x"c9",
x"b9",x"a6", x"21",x"20",
x"20",x"20",x"20",x"20");
begin
--U1:divclk1 port map(clk,clk_100k);
process(clk)
variable cnt:integer range 0 to divide_to_100k;
begin
if(clk'event and clk='1')then cnt:=cnt+1;
if(cnt=divide_to_100k)then cnt:=0;
end if;
if(cnt<divide_to_100k/2) then clk_100k<='0';
else clk_100k<='1';
end if;
end if;
end process;
div_1Hz:
process(clk)
variable cnttemp:integer range 0 to 49999999;
begin
if clk='1' and clk'event then
if cnttemp=49999999 then cnttemp:=0;
else
if cnttemp<25000000 then clkout<='1';
else clkout<='0';
end if;
cnttemp:=cnttemp+1;
end if;
end if;
end process div_1Hz;
disp_time(7)<=DATAIN(3 downto 0)+x"30";
disp_time(6)<=DATAIN(7 downto 4)+x"30";
disp_time(5)<=DATAIN(11 downto 8)+x"30";
disp_time(4)<=DATAIN(15 downto 12)+x"30";
disp_time(3)<=DATAIN(19 downto 16)+x"30";
disp_time(2)<=DATAIN(23 downto 20)+x"30";
disp_time(1)<=DATAIN(27 downto 24)+x"30";
disp_time(0)<=DATAIN(31 downto 28)+x"30";
read_time:
process(time)
begin
end process;
process(clk_100k)
variable cnt1:integer range 0 to 10000;
variable cnt_1:integer range 0 to 1000;
variable code_cnt:integer range 0 to 13;
variable data_cnt:integer range 0 to 480;
begin
if(clk_100k'event and clk_100k='1')then
case current_s is
when s0=>rw<='1';rs<='1';e<='1';cnt1:=cnt1+1;
if cnt1<500 then lcd_rst<='0';
elsif cnt1<1000 then lcd_rst<='1';
elsif cnt1=1000 then
lcd_rst<='1';cnt1:=0;current_s<=s1;
end if;
when s1=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"0c";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s2;
end if;
when s2=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"90";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s3;
end if;
when s3=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf1(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=16 then current_s<=s4;
data_cnt:=0;
end if;
end if;
when s4=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"88";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s5;
end if;
when s5=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf2(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=16 then current_s<=s6;
data_cnt:=0;
end if;
end if;
when s6=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"80";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s7;
end if;
when s7=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf0(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=16 then current_s<=s8;
data_cnt:=0;
end if;
end if;
--动态显示
when s8=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"9a";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s9;
end if;
when s9=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=disp_time(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=8 then current_s<=s10;
data_cnt:=0;
end if;
end if;
--------------------------------------------------------------
when s10=>cnt_1:=cnt_1+1;
if din<=10 then
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"88";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s11;
end if;
else current_s<=s12;
end if;
when s11=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf4(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=8 then current_s<=s0;
data_cnt:=0;
end if;
end if;
when s12=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"88";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s13;
end if;
when s13=>
if cnt_1<1*3 then e<='1';rs<='1';rw<='0';
elsif cnt_1<2*3 then lcd_data<=data_buf3(data_cnt);
elsif cnt_1=2*3 then data_cnt:=data_cnt+1;
elsif cnt_1<100 then e<='0';
end if;
cnt_1:=cnt_1+1;
if cnt_1=100 then cnt_1:=0;
if data_cnt=8 then current_s<=s14;
data_cnt:=0;
end if;
end if;
when s14=>cnt_1:=cnt_1+1;
if cnt_1<1*3 then e<='1';rs<='0';rw<='0';
elsif cnt_1<2*3 then lcd_data<=x"98";
elsif cnt_1<10*3 then e<='0';
elsif cnt_1=10*3 then cnt_1:=0;current_s<=s15;
end if;
when s15=>
展开阅读全文