




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、电子设计自动化课程设计题目: 数字密码锁电路 (1.1) 院(系) 信息科学与工程学院 专 业 15通信工程 届 别 班 级 学 号 姓 名 任课老师 数字密码锁电路,难度系数1.1 实验要求设计一个密码锁,有6位十进制数字密码,串行输入;能设置密码;有开锁和错误指示(led);如果连续输错三次,则一刻钟内不能再开锁。本设计的各个模块由相应的vhdl程序具体实现,并在quartus9.0环境下进行了整体电路的模拟仿真,最终实现“密码锁设计”的要求。实验设计要求6位串行输入,并且由于实验板输入键位的有限,还同时增加了输入密码与设置密码键位的重叠,使密码锁电路输入输出形成一个反馈,通过对输出的判断
2、,让电路自动识别输入的数字是设置的密码还是输入的密码。在程序初始载入实验板时,还要让密码锁的初始设置密码和输入密码相同,从而达到能够初始设置密码的逻辑要求。同时因为实验板输出的led灯有限,还要求设计的密码锁电路的显示能够在输入密码、设置密码和倒计时之间灵活智能选择,从而达到满足使用的要求。密码锁在输入三次错误密码后需要开始一个一刻钟即900秒的倒计时,则需要设计一个逻辑电路使电路能够在输入和错误倒计时之间自由变化。此为本实验设计的主要难点和创新。 目录1. 系统设计 .42. 单元电路设计 .73. 软件设计 .124. 系统测试 .235. 结论 .246. 参考文献 .247. 附录 .
3、258. 其他 .26 系统设计设计要求:设计一个密码锁,有6位十进制数字密码,串行输入;能设置密码;有开锁和错误指示(led);如果连续输错三次,则一刻钟内不能再开锁。系统设计方案:先设计1.0难度的密码锁,此时不需要一刻钟计时模块。该电路首先需要一个输入模块,由于实验板的限制,安排两个键位作为输入,分别实现6个密码位的选择和对确定位密码的输入,所以在输入模块之前,还需要通过计数器来分别得到两个输入;之后设计一个密码合成及选择模块,将得到的6个4位的密码相加得到一个24位的密码,方便之后的比较,同时需要在输入模块添加一个选择,分别确定此时的输入信息是设置密码还是输入密码;将得到的24位设置密
4、码和输入密码分别放到一个确认模块,起到输入确认并且使初始信息清零的作用;最后将两个24位数据放入比较模块,确定密码锁的状态,状态的显示由led灯实现;输出显示led模块从输入模块之前接出,显示当前电路的输入;同时,在计数器之前需要加入消抖模块,使实验板能够稳定输入;在led模块之前需要添加译码器,以输出正确显示。下图为1.0密码锁各个模块及接线。 完成1.0难度密码锁之后设计一个计数器,通过对密码输入确认和输出状态的计数,当输入错误达到三次时,开始一个一刻钟的计时,由另外一个计数器完成。该计数器的输入还需要一个50m分频模块,得到一个稳定的每秒输出一个电平跳变的输入;为了将900秒的计时显示到
5、led上,需要用除法器将计时的各个位拆分出来,再通过译码器显示到led上。最后还需要一个输出选择模块,通过对3计数器的数据识别,选择当前led输出的是900秒计时还是当前输入数据。下图为1.1难度密码锁最终的各个模块及接线。 其他方案:除上述方法外,还可以将比较器放在输出选择模块之前,这样能够让程序在开发板上仿真时,位选之后不会将上一位的输入连带到本位;如果去掉输入选择模块,可以增加一个输入为设置密码输入,即将输入密码和设置密码的输入分开;倒计时模块采用的是从900倒计时到0,即“1110000110”到“0000000000”,然后输出cout为1;该程序也可以从“0000000000”累加
6、到“1110000110”计数;单元电路设计消抖模块:消除按键难以避免的抖动,以得到稳定的输入;计数器:本实验分别用到了3进制、6进制和10进制的计数器,每计数到一定量时计数器清零并输出一个高电平; 密码合成及选择模块:将得到的6个4位的密码合成一个24位的密码并输出,方便之后的密码比较,密码合成通过&完成,通过对输出状态反馈(开锁输出1,锁存输出0)的识别,判断当前输入的数据是设置密码还是输入密码,作两个输出;确认模块:将得到的输入密码和设置密码确认输出到比较器,同时在程序载入实验板时,还未有输入的情况下,能够默认输入密码和设置密码都是24位0,使两者初始值相等(此时比较器输出为1,反馈到该
7、模块,输入的数据为设置密码),达到能设置密码的状态;比较模块:对得到的输入密码和设置密码进行比较,输出显示当前密码锁是锁存0还是开锁状态1;译码器:将得到的数据读取,使其输出的数据能够显示到led上;led:将6位密码显示在led上;50m分频:每秒稳定输出一个电平跳变;输出选择:通过对3进制计数器的数据读取(输入错误三次输出cout为1,否则为0),选择输出是当前密码输入、设置密码输入还是900秒计时;除法器:将900秒计时的百位、十位和个位拆分出来,使其能通过译码器显示到led上。(该模块主要通过lpm_divide和lpm_constant实现,900秒的计时数据分别除常数100和10,
8、再通过对商的后四位数据的读取得到各个位的大小)下图为除法器各模块及接线: led第二位显示默认为0模块:将实验没有用到的led第二位显示输出默认为不显示;led输出选择模块:选择led是显示倒计时还是此时输入密码软件设计软件:quartus9.0(cyclone ep2c5t144c8);硬件:对应的fpga开发板程序清单1. 消抖模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity xiaodou is port( k_in,clk:in std_logic; k_out:out s
9、td_logic);end;architecture one of xiaodou issignal k_pre:std_logic;signal count:integer range 0 to 3999999;begin process(clk,k_in) begin if clkevent and clk=1 then if k_in=k_pre then if count3999999 then count=count+1; else count=3999999; end if; else count=0; end if; k_pre=k_in; end if; if count=39
10、99999 then k_out0) ; -计数器异步复位 elsif clkevent and clk=1 then -检测时钟上升沿 if en = 1 then -检测是否允许计数(同步使能) if cqi 0); -大于9,计数值清零 end if; end if; end if; if cqi = 9 then cout = 1; -计数大于9,输出进位信号 else cout = 0; end if; cq 0) ; -计数器异步复位 elsif clkevent and clk=1 then -检测时钟上升沿 if en = 1 then -检测是否允许计数(同步使能) if c
11、qi 0); -大于9,计数值清零 end if; end if; end if; if cqi = 5 then cout = 1; -计数大于9,输出进位信号 else cout = 0; end if; cq 0) ; elsif clkevent and clk=0 then if b 0); end if; end if; if b = 3 then y = 1; else y = 0; end if; end process; end one;5. 输入模块library ieee; use ieee.std_logic_1164.all; entity zongxuan is p
12、ort( d: in std_logic_vector(3 downto 0); b: in std_logic_vector(3 downto 0); code0,code1,code2,code3,code4,code5:out std_logic_vector(3 downto 0);end entity zongxuan;architecture behav of zongxuan is begin process(b) begin if b=0000 then code0=d; elsif b=0001 then code1=d; elsif b=0010 then code2=d;
13、 elsif b=0011 then code3=d; elsif b=0100 then code4=d; else code5=d; end if;end process; end behav; 6. 密码合成及选择模块library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jicun is port( p0,p1,p2,p3,p4,p5:in std_logic_vector(3 downto 0); change:in std_logic; rcode,icode:out st
14、d_logic_vector(23 downto 0); end jicun; architecture bhv of jicun is signal code:std_logic_vector(23 downto 0); begin process(change) begin code=p0&p1&p2&p3&p4&p5; if change=1 then rcode = code; else icode = code; end if;end process; end bhv;7. 输出确认模块library ieee; use ieee.std_logic_1164.all; entity
15、 queren is port( incode:in std_logic_vector(23 downto 0); outcode:out std_logic_vector(23 downto 0); k:in std_logic); end queren;architecture bhv of queren is begin process (k) begin if k=0 then outcode = incode ; end if; end process; end bhv;8. 比较模块library ieee; use ieee.std_logic_1164.all; entity
16、bijiao is port( rcode,icode:in std_logic_vector(23 downto 0); l:out std_logic); end bijiao;architecture bhv of bijiao is begin process (rcode,icode) begin if icode /= rcode then l = 0; else l = 1; end if; end process; end bhv;9. 译码器library ieee;use ieee.std_logic_1164.all;entity yimaqi is port( a :i
17、n std_logic_vector(3 downto 0); y :out std_logic_vector(6 downto 0);end entity yimaqi;architecture one of yimaqi isbegin y =1000000 when a= 0000 else 1111001 when a= 0001 else 0100100 when a= 0010 else 0110000 when a= 0011 else 0011001 when a= 0100 else 0010010 when a= 0101 else 0000010 when a= 0110
18、 else 1111000 when a= 0111 else 0000000 when a= 1000 else 0010000 when a= 1001 else 0001000 when a= 1010 else 0000011 when a= 1011 else 1000110 when a= 1100 else 0100001 when a= 1101 else 0000110 when a= 1110 else 0001110 when a= 1111 else null;end architecture one;10.900秒计时library ieee;use ieee.std
19、_logic_1164.all;use ieee.std_logic_unsigned.all;entity daojishi is port ( clk,en :in std_logic; led0 : out std_logic_vector(9 downto 0); cout: out std_logic); end daojishi;architecture behav of daojishi isbegin process(clk,en) variable led:std_logic_vector(9 downto 0); begin if en=0 then led:=111000
20、0100;led0=1110000100; elsif clkevent and clk=1 then led:=led-1; end if;if led=0000000000 then cout=1;else cout=0;end if; led0=led; end process;end behav;11.计时除100得商取后四位library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jiusi is port( a:in std_logic_vector(9 downto 0); b:
21、out std_logic_vector(3 downto 0); end jiusi;architecture one of jiusi is begin process(a) begin b=a(3 downto 0); end process; end;12.计时除100得余数再除10得商取后四位library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity qisi is port(a:in std_logic_vector(6 downto 0); b:out std_logic_vect
22、or(3 downto 0); end qisi;architecture one of qisi is begin process(a) begin b=a(3 downto 0); end process; end;13.50m分频library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt50m is port(clk:in std_logic; cout:out std_logic); end cnt50m; architecture one of cnt50m is begin
23、process(clk) variable c:integer range 0 to 49999999; begin if clkevent and clk=1 then if c=49999999 then cout=1; c:=0; else c:=c+1; cout=0; end if; end if; end process;end;14.选择是否读取输出状态library ieee;use ieee.std_logic_1164.all;entity xuan is port ( a: in std_logic; b:in std_logic; y : out std_logic);
24、end entity xuan;architecture one of xuan isbegin process (b,a) begin if b=0 then y = a ; else y=1; end if; end process;end architecture one ;15. 输出选择模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity xuanze is port(a,b:in std_logic_vector(6 downto 0); s:in std_logic; y
25、:out std_logic_vector(6 downto 0); end xuanze ;architecture one of xuanze is begin process(s)begin if s=0 then y=a; else y=b;end if;end process;end;16. led显示library ieee;use ieee.std_logic_1164.all;entity led_ctrl is port( clk_50m : in std_logic; d1, d2, d3, d4, d5, d6, d7, d8: in std_logic_vector(6
26、 downto 0); led1, led2, led3, led4, led5, led6, led7, led8: out std_logic; dout: out std_logic_vector(6 downto 0);end led_ctrl;architecture one of led_ctrl issignal cnt: integer range 49999 downto 0;signal seg_num: integer range 7 downto 0;beginprocess(clk_50m) beginif clk_50mevent and clk_50m=0 the
27、nif cnt49999 then - 1/1000hzcnt = cnt+1;elsecnt = 0;seg_num led1=0; led2=1; led3=1; led4=1; led5=1; led6=1; led7=1; led8=1; dout led1=1; led2=0; led3=1; led4=1; led5=1; led6=1; led7=1; led8=1; dout led1=1; led2=1; led3=0; led4=1; led5=1; led6=1; led7=1; led8=1; dout led1=1; led2=1; led3=1; led4=0; led5=1; led6=1; led7=1; led8=1; dout led1=1; led2=1; led3=1; led4=1; led5=0; led6=1; led7=1; led8=1; dout led1=1; led2=1; led3=1; led4=1; led5=1; led6=0; led7=1; led8=1; dout led1=1; led2=1; led3=1; led4=1; led5=1; led6=1; led7=0; led8=1; dout led1=1; led2=1; led
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- “醉驾”型危险驾驶罪综合治理模式的实践探索与反思
- 农村供水绩效管理办法
- 标准化管理下的消毒供应中心质量控制体系构建与实践
- 民政小区车辆管理办法
- 小学篮球社团活动方案
- 220kV变电站工程试运行流程与解析
- 古代文学专题:经典文本与思想传承研究
- 公共平台建设管理办法
- 大豆籽粒营养成分与豆乳品质的关系分析
- 高考期间食堂食品安全保障措施
- 2024年江苏三支一扶真题
- 《危险货物港口作业重大事故隐患判定指南》解读与培训
- 主、被动防护网施工方案-图文
- 2025年初中语文文学常识:常考100题汇编
- 君易和文化课件
- 药食同源106种25年4月更新
- 2025年江苏省南通市中考英语适应性试卷(A卷)
- 无机盐在化妆品行业的应用研究考核试卷
- 猪场生产安全
- 2025年度苗圃土地承包合同-观光树种植与生态旅游产业链投资合作框架
- 《城市供水》课件
评论
0/150
提交评论