VHDL密码锁实验报告.docx
- 文档编号:29739820
- 上传时间:2023-07-26
- 格式:DOCX
- 页数:27
- 大小:1.13MB
VHDL密码锁实验报告.docx
《VHDL密码锁实验报告.docx》由会员分享,可在线阅读,更多相关《VHDL密码锁实验报告.docx(27页珍藏版)》请在冰豆网上搜索。
VHDL密码锁实验报告
华南师大学实验报告
学生:
小澎
学号:
***********_
专业:
通信工程
年级班级:
11级电通6C
课程名称:
可编程数字系统
实验项目:
VHDL设计一密码锁
试验时间:
2013年05月18日
********
一、课程设计目的
熟悉EDA工具,掌握用VHDL语言进行数字系统设计的基本方法和流程,提高工程设计实践能力。
二、设计任务
设计一密码锁,用VHDL语言描述,用QuartusII工具编译和综合,并在实验板上实现,撰写实验报告。
数字锁即电子密码锁,锁有预置密码,如果输入代码与锁密码一致,锁被打开;否则,应封闭开锁电路,若多次输入错误密码,应发出报警信号。
三、功能要求与技术指标
本设计设计一个4位数字锁,并验证其操作。
1、基本功能:
(1)开锁密码为4位十进制数,通过按钮输入密码,输入的密码在4个数码管上显示,若与锁预置的密码一致,输出开锁信号(以点亮一个LED灯表示开锁)。
(2)按钮开关输入须消抖处理。
2、扩展功能:
(1)用户可以设置锁的密码;
(2)若输入密码三次不正确,输出报警信号,报警信号可以通过闪烁LED或某个数码管上小数点指示。
(3)设置一个复位按键,忘记密码后可通过该复位按键恢复出厂原始密码,如原始密码为“1234”;
(4)其它实用功能。
四、设计原理
在数字电路设计中,自顶向下设计方法的主要思想是对数字系统进行划分,将复杂的设计原理简化为相对简单的模块设计,不同的模块用来完成数字系统中某一部分的具体功能。
此密码锁的设计可以分为以下几个模块:
密码锁原理框图
五、系统分析
1、根据原理框图:
系统大致可分为时钟模块,显示模块,控制模块。
时钟模块:
密码锁的工作时钟由外部晶振提供,时钟频率为50Mhz。
对CLK进行分频输出三路时钟CLK1Khz,CLK1,CLK2,频率分别为1Khz,5hz,1hz。
由此,时钟分频模块原理框图如下:
CLK
显示模块:
数码管动态扫描模块以及数码管显示模块的时钟频率分别由CLK1Khz和CLK提供。
数码管动态扫描模块的原理是利用人体的视觉暂留特性,只要每秒扫描次数大于25次,就感觉数码管一直在亮。
数码管显示模块由四个数码管分别显示四位十进制密码。
四个数码管为共阳极连接,其中一段输入低电平则点亮,否则不亮;且由各自位选信号控制,被选通数码管则显示数据,其余关闭。
控制模块:
根据密码锁的功能可划分为以下五个模块。
按键消抖模块:
消抖是为了避免在按键按下或是抬起时电平剧烈抖动带来的影响。
一般来说,软件消抖的方法是不断检测按键值,直到按键值稳定。
实现方法:
假设未按键时输入1,按键后输入为0,抖动时不定。
可以做以下检测:
检测到按键输入为0之后,开始计数,延时10ms,再次检测,如果按键还为0,那么就认为有按键输入。
延时的10ms恰好避开了抖动期。
数码管移位模块:
当CLK时钟上升沿到来时,设置按键S3对数码管进行移位控制。
通过闪烁的方式显示当前其控制的数码管位置。
数码管计数模块:
当CLK时钟上升沿到来时,设置按键S2对数码管进行加数控制。
密码检验模块:
该模块的作用是将输入的密码跟程序中预置的密码进行对比,如果一样,则密码锁开锁。
在这里值得注意的是设“1111”为初始密码,如果修改密码后但是又忘记了密码,重新下载或者按复位键(rst)之后只要输入的密码为“1111”则都可通过密码锁。
此模块是整个设计的核心,它实现密码锁的逻辑功能。
在任何时候按动密码初始化按键密码设置为程序初始化密码值“1111”代码为4位二进制数,当输入代码的位数和位值与锁给定的密码一致,且按规定程序开锁时,方可开锁,并点亮开锁指示灯且数码管显示“PASS”字样。
否则,系统进入“错误”状态,并闪烁LED发出报警信号,且数码管显示“FFFF”字样。
密码设置模块:
为防止任意进行密码修改,必须在正确输入密码后,才能重新设置密码。
输入正确密码后,锁打开,同时,密码修改控制信号M置高电平,就可直接进行修改密码的操作。
修改密码实质就是用输入的新密码去取代原来的旧密码,按确定键,存储新密码。
此功能设置方便,性好。
六、程序设计
LIBRARYieee;
USEieee.std_logic_1164.all;
USEieee.std_logic_arith.all;
USEieee.std_logic_unsigned.all;
entitymimasuois
port(clk:
instd_logic;
start,num,keyr,set,rst:
instd_logic;
display:
outstd_logic_vector(7downto0);
seg:
outstd_logic_vector(3downto0);
led:
outstd_logic);
endmimasuo;
architecturelockofmimasuois
signalt2:
integerrange0to50000;
signalt3:
integerrange1to10000000:
=1;
signalt4:
integerrange1to50000000:
=1;
signalclk1khz:
std_logic;
signalclk1,clk2:
std_logic;
signalk:
integerrange0to3:
=0;
signalm:
integerrange0to1;
signalcount1:
integerrange0to1:
=0;
signalcount2:
integerrange0to3;
signalcount3:
integerrange0to100:
=0;
signalcount4:
integerrange0to1:
=0;
signalnumcnt,keyrcnt,startcnt,setcnt,rstcnt:
integerrange0to50000000;
signalnumfilt,keyrfilt,startfilt,setfilt,rstfilt:
std_logic;
signala,b,c,d:
integerrange0to9;
signala1,b1,c1,d1:
integerrange0to9:
=1;
begin
-------------------------------------------------------分频模块
process(clk)
begin
ifrising_edge(clk)then
ift2=50000then
t2<=0;
clk1khz<='1';
else
t2<=cnt2+1;
clk1khz<='0';
endif;
endif;
endprocess;
process(clk)
begin
ifrising_edge(clk)then----产生周期为0.2s的时钟信号
ift3=10000000then
t3<=1;
elset3<=cnt3+1;
endif;
ift3<5000000then
clk1<='1';
elseclk1<='0';
endif;
endif;
endprocess;
process(clk)
begin
ifrising_edge(clk)then----产生周期为1s的时钟信号
ift4=50000000then
t4<=1;
elset4<=cnt4+1;
endif;
ift4<25000000then
clk2<='1';
elseclk2<='0';
endif;
endif;
endprocess;
------------------------------------------------------动态扫描
process(clk1khz)
begin
ifrising_edge(clk1khz)then
ifk=3then
k<=0;
else
k<=k+1;
endif;
endif;
ifm=1then
casekis
when0=>seg<="0111";--'0'
when1=>seg<="1011";--'1'
when2=>seg<="1101";--'2'
when3=>seg<="1110";--'3'
endcase;
elseifm=0andcount3=3then
casekis
when0=>seg<="0111";--'0'
when1=>seg<="1011";--'1'
when2=>seg<="1101";--'2'
when3=>seg<="1110";--'3'
endcase;
else
casecount2is
when0=>
casekis
when0=>ifclk2='1'thenseg<="1111";
else
seg<="0111";--'0'
endif;
when1=>seg<="1011";--'1'
when2=>seg<="1101";--'2'
when3=>seg<="1110";--'3'
endcase;
when1=>
casekis
when1=>ifclk2='1'thenseg<="1111";
else
seg<="1011";--'0'
endif;
when0=>seg<="0111";--'1'
when2=>seg<="1101";--'2'
when3=>seg<="1110";--'3'
endcase;
when2=>
casekis
when2=>ifclk2='1'thenseg<="1111";
else
seg<="1101";--'0'
endif;
when1=>seg<="1011";--'1'
when0=>seg<="0111";--'2'
when3=>seg<="1110";--'3'
endcase;
when3=>
casekis
when3=>ifclk2='1'thenseg<="1111";
else
seg<="1110";--'0'
endif;
when1=>seg<="1011";--'1'
when2=>seg<="1101";--'2'
when0=>seg<="0111";--'3'
endcase;
endcase;
endif;
endif;
endprocess;
------------------------------------------------------移位
process(clk,keyrfilt)
begin
ifrising_edge(clk)then
if(keyrfilt='1')then
ifcount2=3then
count2<=0;
else
count2<=count2+1;
endif;
endif;
endif;
endprocess;
-------------------------------------------------------计数
process(clk,numfilt)
begin
ifrising_edge(clk)then
ifnumfilt='1'then
ifcount2=0then
ifa=9then
a<=0;
elsea<=a+1;
endif;
endif;
ifcount2=1then
ifb=9then
b<=0;
elseb<=b+1;
endif;
endif;
ifcount2=2then
ifc=9then
c<=0;
elsec<=c+1;
endif;
endif;
ifcount2=3then
ifd=9then
d<=0;
elsed<=d+1;
endif;
endif;
endif;
endif;
endprocess;
------------------------------------------------显示
process(clk)
begin
ifm=1then----开锁时且按一下start,显示PASS
ifcount1=1then
ifk=0then
display<="10001100";
endif;
ifk=1then
display<="10001000";
endif;
ifk=2then
display<="10010010";
endif;
ifk=3then
display<="10010010";
endif;
else-----显示PASS后,
ifk=0then再按一下start,
caseais--hgfedcba显示原先密码
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
ifk=1then
casebis--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
ifk=2then
casecis--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
ifk=3then
casedis--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
endif;
elseifm=0andcount3=3then----连续错误三次,则显示FFFF
ifk=0then
display<="10001110";
endif;
ifk=1then
display<="10001110";
endif;
ifk=2then
display<="10001110";
endif;
ifk=3then
display<="10001110";
endif;
else
ifk=0then
caseais--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
ifk=1then
casebis--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
endif;
ifk=2then
casecis--hgfedcba
when0=>display<="11000000";--0
when1=>display<="11111001";--1
when2=>display<="10100100";--2
when3=>display<="10110000";--3
when4=>display<="10011001";--4
when5=>display<="10010010";--5
when6=>display<="10000010";--6
when7=>display<="11111000";--7
when8=>display<="10000000";--8
when9=>display<="10010000";--9
endcase;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VHDL 密码锁 实验 报告