《基于Verilog的数字密码锁设计.doc》由会员分享,可在线阅读,更多相关《基于Verilog的数字密码锁设计.doc(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、课程设计报告课程设计题目:基于Verilog的数字密码锁设计学号:201520070209学生姓名:尹景兴专业:通信工程班级:1521301指导教师:钟凯2018年1月12日目 录一、课程设计内容 1 -二、实现思路- 1 -1。解锁过程- 1 2.报警过程- 1 3。重置密码过程 1 三、实现程序 2 四、仿真验证 5 -1.解锁过程 5 2。报警过程- 6 3。重置密码过程- 8 -五、设计心得- 11 一、 课程设计内容设计一个4位串行数字密码锁,要求如下:1. 开锁密码为4位二进制,当输入密码与锁内给定的密码一致时,方可开锁。否则进入“错误”状态,发出报警信号。2. 锁内的密码可调。3
2、. 串行数字密码锁的报警,直到按下复位开关,才停下.此时,数字密码锁又自动等待下一个开锁状态。二、 实现思路1. 解锁过程密码锁出厂之前预设一个初始密码,在本课程设计中将其预设为0101。在密码锁上锁状态下,输入正确密码,密码锁打开.2. 报警过程当输入的密码与锁内密码不一致时,蜂鸣器响起,直到按下取消按键,蜂鸣器才停止鸣叫。3. 重置密码过程重置密码时,需先验证原密码是否正确.当输入原密码正确,才可以输入新密码,设置新密码为锁内密码。三、 实现程序module coded_lock(clk,in,set,pause,value1,value2,store,bee,status,temp_se
3、t,ook); input clk,in,set,pause; output reg bee = 0; output reg status = 0; output regtemp_set = 0; output regook = 0;output reg3:0 value1; output reg3:0 value2; output reg3:0 store;regen = 1;reg2:0 i = 0;reg2:0 j = 0;reg2:0 k = 0;reg2:0 count1 = 0;reg2:0 count2 = 0;reg2:0 count3 = 0;reg3:0 keynum =
4、4b0101; always (posedgeclk) beginif(set = 1) forktemp_set = 1; value1 = 4bxxxx; value2 = 4bxxxx; store = 4bxxxx;i = 0; j = 0; k = 0;ook = 0; count1 = 0; count2 = 0; count3 = 0; join end always (posedgeclk) beginif(temp_set = 0) begin case(en,in) 2b11: begin value1i = 1b1; i = i + 1; count1 = count1
5、+ 1;end 2b10: begin value1i = 1b0; i = i + 1; count1 = count1 + 1;endendcase end end always (posedgeclk) beginif(count1 = 4) beginif(value1 = keynum) status = 1; else bee = 1;i = 0; count1 = 0; value1 = 4bxxxx; end end always (posedgeclk) beginif(pause = 1) bee = 0; end always (posedgeclk) beginif(t
6、emp_set = 1 & ook = 0) begin case(en,in) 2b11: begin value2j = 1b1; j = j + 1; count2 = count2 + 1;end 2b10: begin value2j = 1b0; j = j + 1; count2 = count2 + 1;endendcase end end always (posedgeclk) beginif(count2 = 4) beginif(value2 = keynum)ook = 1; j = 0; count2 = 0; value2 = 4bxxxx; end end alw
7、ays (posedgeclk) beginif(ook = 1) begin case(en,in) 2b11: begin storek = 1b1; k = k + 1; count3 = count3 + 1;end 2b10: begin storek = 1b0; k = k + 1; count3 = count3 + 1;endendcase end end always (posedgeclk) beginif(count3 = 4) beginkeynum = store;temp_set = 0;ook = 0; k = 0; count3 = 0; end end en
8、dmodule四、 仿真验证1. 解锁过程测试平台代码:timescale 1ns/1nsmodule text;regclk,set,pause;reg in; wire bee,status,ook;wire3:0 value1,value2;wire3:0 store; wire temp_set;coded_lock temp(.clk(clk),.in(in),。set(set),.pause(pause),.bee(bee),。ook(ook),.status(status),。value1(value1),。value2(value2),。store(store),.temp_s
9、et(temp_set); always #10 clk = clk; initial forkclk = 0; in = 1bx; set = 0; pause = 0; join initial begin #123 in = 1b1; 23 in = 1bx; 45 in = 1b0; 23 in = 1bx; 45 in = 1b1; 23 in = 1bx; #45 in = 1b0; #23 in = 1bx; end endmodule如图,当输入预设密码0101时,图中status由0变为1,表示密码锁打开。2. 报警过程测试平台代码:timescale 1ns/1nsmodu
10、le text3;regclk,set,pause;reg in; wire bee,status,ook;wire3:0 value1,value2;wire3:0 store; wire temp_set;coded_lock temp3(.clk(clk),。in(in),。set(set),。pause(pause),.bee(bee),.ook(ook),。status(status),.value1(value1),。value2(value2),.store(store),.temp_set(temp_set)); always #10 clk = clk; initial fo
11、rkclk = 0; in = 1bx; set = 0; pause = 0; join initial begin #123 in = 1b1; #23 in = 1bx; #45 in = 1b1; 23 in = 1bx; #45 in = 1b0; 23 in = 1bx; 45 in = 1b0; 23 in = 1bx; 123 pause = 1; #23 pause = 0; end endmodule如下图,当输入密码0011时,与锁内密码不一致,bee由0变为1,表示蜂鸣器响起.当按下pause按钮时,bee由1变为0,表示蜂鸣器停止鸣叫。3. 重置密码过程测试平台代码:
12、timescale 1ns/1nsmodule text2;regclk,set,pause;reg in; wire bee,status,ook;wire3:0 value1,value2;wire3:0 store; wire temp_set;coded_lock temp2(。clk(clk),.in(in),.set(set),。pause(pause),.bee(bee),.ook(ook),。status(status),.value1(value1),.value2(value2),。store(store),.temp_set(temp_set)); always #10
13、clk = clk; initial forkclk = 0; in = 1bx; set = 0; pause = 0; join initial begin #123 set = 1; 21 set = 0; 123 in = 1b1; 21 in = 1bx; 45 in = 1b0; 21 in = 1bx; #45 in = 1b1; 21 in = 1bx; 45 in = 1b0; 21 in = 1bx; 125 in = 1b0; #21 in = 1bx; 45 in = 1b1; 21 in = 1bx; #45 in = 1b0; 21 in = 1bx; 45 in
14、= 1b1; #21 in = 1bx; #125 in = 1b0; #21 in = 1bx; #45 in = 1b1; 21 in = 1bx; 45 in = 1b0; #21 in = 1bx; #45 in = 1b1; 21 in = 1bx;end endmodule如下图,当正确输入预设密码0101时,ook由0变为1,表示可以更改密码,更改密码为1010。接着,输入新密码1010,status由0变为1,表示密码锁被新密码打开,如下图。五、 设计心得通过这次课程设计,我更深入熟悉了Verilog编程的各个过程和原理,并且,成功地做出了一个产品的简化模型极大地挺高了我的学习
15、兴趣。当然,设计过程中也遇到了各种问题和困难,我极力克服,过后感觉受益匪浅。我会再接再厉的。Bingo!- 8 -东华理工大学课程设计评分表学生姓名:尹景兴班级:1521301 学号:201520070209课程设计题目:基于Verilog的数字密码锁设计项目内容满分实评选题能结合所学课程知识、有一定的能力训练。符合选题要求(5人一题)10工作量适中,难易度合理10能力水平能熟练应用所学知识,有一定查阅文献及运用文献资料能力10理论依据充分,数据准确,公式推导正确10能应用计算机软件进行编程、资料搜集录入、加工、排版、制图等10能体现创造性思维,或有独特见解10成果质量总体设计正确、合理,各项技术指标符合要求。10说明书综述简练完整,概念清楚、立论正确、技术用语准确、结论严谨合理;分析处理科学、条理分明、语言流畅、结构严谨、版面清晰10设计说明书栏目齐全、合理,符号统一、编号齐全.格式、绘图、表格、插图等规范准确,符合国家标准10有一定篇幅,字符数不少于500010总分100指导教师评语:指导教师签名:年月日
限制150内