EDA考试设计报告电子锁码器.doc
-EDA考试设计报告调研题目:电子锁码器院系班级:小组成员:指导教师:时 间:联系方式:评阅成绩:电子锁码器Electronic lock transcoder【 abstract 】 : in response to the requirements of the test subjects teachers do design. This design can realize the eight decimal number lock code, lock within a output that can signal (high level effective).【 key words 】 : lock code, decimal ,make can【摘要】:为响应科目教师对考试的要求而做的设计。本设计能实现八位十进制数以内的锁码,锁定一个输出使能信号高电平有效。【关键词】:锁码 十进制 使能引言该锁码器分主状态分三个待机状态,密码状态,完毕状态,密码状态再分三个次状态输入状态,修改状态,运行状态,能够设置8位以内十进制数的任何密码,每个状态都有不同的状态灯显示,当输入密码正确可以选择改变密码或者调至运行状态输出一个使能信号。正文一、待机状态待机状态中,除输入正确状态灯外的四个状态灯显示为"0001,当使用者拨动回车键enter、上升沿有效,使go信号置1,锁码器会从待机状态进入密码状态,进展输码、改码等功能。二、密码状态密码状态可用的前提是go信号为高电平,且密码输入状态立即可用。1密码输入状态密码输入状态的四个状态灯显示为"0010。当状态灯这样显示时使用者可以输入想要输入的八位以内的十进制数然后拨动回车键,当输入的临时数temp_password等于已存储的密码password时,正确输入状态灯亮。当输入的临时数不等于已存储的锁定密码,正确输入状态灯不亮且立即跳至主状态中的完毕状态。当正确输入状态灯亮时,有两种选择。拨动回车键调至运行状态;拨动改变键change_password、上升沿有效进入密码修改状态。2密码修改状态密码修改状态的四个状态灯显示为"0100,这是正确输入状态灯依然在亮。当状态灯这样显示时使用者可以输入想要的八位以内的十进制数。当输入完成时,使用者有两个选择:拨动改变键,把已输入的数存储为密码;拨动回车键,直接进入运行状态,因为正确输入状态灯依然亮,正确输入仍然有效当使用者觉得所修改的密码不适宜情况下需要用到。当使用者输入完成,并拨动改变键把想要的密码存储完后,拨动回车键就可进入运行状态。只要正确输入状态灯亮时,拨动回车键都能是锁码器进入运行状态3运行状态运行状态的四个状态灯显示为"1000,这时正确输入状态灯已熄灭。当锁码器处于运行状态时,锁定的输出使能信号为1。当使用者觉得已经完成运行时拨动回车键就能使锁码器进入主状态中的完毕状态,并使输出使能信号、go信号置0,且使次状态回到输入状态。三、完毕状态完毕状态没有任何操作,会有一个简单的流水灯效果,倒数一段不长的时间后自动返回待机状态。四、完毕语在设计根本完成时,还存在很多细节上的问题。例如在正确输入之后想要进入改变密码状态而未拨动改变键时,如果拨动数字选项键,会使到进入改变状态后临时数的初始值不为空全0。虽然比拟繁琐,不过经过一步步耐心的在modelsim仿真验证后,根本上已经能让使用者正常、方便的使用该锁码器了。由于de2板上的开关存在严重的抖动现象,所以该锁码器中除了电平触发的复位键外,其他全部使用到的开关都带有去抖动功能。最后,感谢郭晓云教师的悉心指导。参考文献:EDA技术与应用 张建 邓桃丽 邓锐 朱旭东 编著单片机技术及系统设计 周美娟 肖来胜 编著源程序:-模块名称:程序包模块-模块功能:设置设计中使用到的两个类型。library ieee;use ieee.std_logic_1164.all;packageMy_package istype state1 is (standby_state,password_state,end_state);type state2 is (input_state,change_state,run_state);end My_package;-模块名称:待机状态、密码输入准备状态、完毕状态转换-模块功能:在待机状态下按一下回车键进入密码输入准备状态,-在密码输入准备状态下发出一个complete的信号进入完毕状态,-完毕状态中自动计数一秒后回到待机状态。library ieee;use ieee.std_logic_1164.all;use work.My_package.all;entity Standby_password_end_transition is port (clk:in std_logic;-时钟输入reset:in std_logic;-复位键enter:in std_logic;-回车键complete:in std_logic;-完成运行信号lkd_state:buffer state1;-模块状态信号go:out std_logic-密码输入模块准许信号);end Standby_password_end_transition;architecture behavior of Standby_password_end_transition issignal starting:std_logic:='0'-待机到密码输入准备状态的允许信号signal finishing:std_logic:='0'-密码输入准备状态到完毕状态的允许信号signal ending:std_logic:='0'-完毕状态到待机状态的的允许信号signal count:integer range 0 to 49999999 :=0;-计数器signal count_delay:integer range 0 to 999999 :=0;signal start:std_logic:='0'begin-进程名称:三状态转换控制进程-进程功能:在不同的准许信号下三状态转换process (reset,clk,starting,finishing,lkd_state)beginif reset='1' then lkd_state<=standby_state;elsif rising_edge(clk) thencase lkd_state iswhen standby_state =>-待机状态的处理if starting='1' thenlkd_state<=password_state;else lkd_state<=standby_state;end if;when password_state =>-密码准备状态的处理if finishing='1' thenlkd_state<=end_state;elselkd_state<=password_state;end if;when end_state =>-完毕状态的处理if ending='1' then lkd_state<=standby_state;else lkd_state<=end_state;end if;end case;end if;end process;-进程名称:starting允许信号的控制-进程功能:starting允许信号的控制,附去抖动process (enter,lkd_state,reset)beginif reset='1' thenstart<='0'elsif lkd_state=standby_state thenif rising_edge(enter) thenstart<='1'end if;elsestart<='0'end if;end process;process(clk,start,count_delay,enter)beginif rising_edge(clk) thenif start='1' thenif count_delay<999999 thencount_delay<=count_delay+1;elsif enter='1' thenstarting<='1'elsestarting<='0'end if;elsecount_delay<=0;starting<='0'end if;end if;end process;-进程名称:go信号的控制-进程功能:go信号的控制process (lkd_state)beginif lkd_state=password_state thengo<='1'else go<='0'end if;end process;-进程名称:finishing信号的控制-进程功能:finishing信号的控制process(lkd_state,complete)beginif lkd_state=password_state thenif rising_edge(complete) thenfinishing<='1'end if;else finishing<='0'end if;end process;-进程名称:ending信号的控制-进程功能:ending信号的控制process (lkd_state,clk,reset,count)beginif rising_edge(clk) thenif lkd_state=end_state then if count<49999999thencount<=count+1;elsecount<=0;ending<='1'end if;else ending<='0'count<=0;end if;end if;end process;end behavior;-模块名称:解码锁码-模块功能:按回车键,假设密码输入正确可选择改变密码或直接运行run- 按回车键跳完毕状态end_state;- 不正确转至完毕状态。- 锁定新密码后按回车键跳到运行状态;- 按回车键调至借宿状态。library ieee;use ieee.std_logic_1164.all;use work.My_package.all;entity Unlock isport(clk:in std_logic;-时钟输入change_password:in std_logic;-改变密码键上升沿有效enter:in std_logic;-回车键上升沿有效reset:in std_logic;-复位开关高电平电平有效run:out std_logic;-运行允许信号高电平有效-Standby_password_end_transition模块信号go:in std_logic;-密码输入模块准许信号complete:out std_logic;-运行完毕信号-临时密码模块用信号password_allow :out std_logic;-密码输入允许clr_t:out std_logic;-临时密码清零信号ok:buffer std_logic;-回车键信号change:buffer std_logic;-change_password信号count_pn_enable:out std_logic;-count_pn使能信号set_count_pn:out std_logic;-count_pn置数信号password:buffer std_logic_vector(31 downto 0);-设定的密码temp_password:in std_logic_vector(31 downto 0);-临时密码p_state:buffer state2;-Unlock状态信号correct_input:in std_logic;-密码输入正确信号d_complete:in std_logic-complete控制信号);end Unlock;architecture behavior2 of Unlock issignal clr_o:std_logic:='0'-ok清零信号signal clr_c:std_logic:='1'-change清零信号signal clr_cpl:std_logic:='1'-complete清零signal set_cpl:std_logic:='0'-complete置数signal pass_word:std_logic_vector(31 downto 0):="0000"-过渡密码signal count_delay1:integer range 0 to 999999 :=0;signal count_delay2:integer range 0 to 999999 :=0;signal oo:std_logic:='0'signal clr_oo:std_logic:='0'signal cc:std_logic:='0'signal clr_cc:std_logic:='0'begin-进程名称:输入状态、改变状态、运行状态转换-进程功能:输入状态、改变状态、运行状态的控制、处理process(clk,reset,p_state,go,correct_input,change,ok,temp_password)beginif rising_edge(clk)thenif reset='1'then-复位p_state<=input_state;clr_cpl<='1'set_cpl<='0'clr_t<='1'run<='0'pass_word<="0000"count_pn_enable<='0'set_count_pn<='0'elsif go='1'thencase p_state iswhen input_state=>-输入状态的处理run<='0'clr_cpl<='0'set_cpl<='0'count_pn_enable<='1'set_count_pn<='0'clr_t<='0'if correct_input='1' thencount_pn_enable<='0'set_count_pn<='1'if ok='1' thenp_state<=run_state;clr_t<='1'set_count_pn<='0'elsif change='1' thenp_state<=change_state;set_count_pn<='0'clr_t<='1'end if;end if;when change_state=>-改变状态的处理clr_t<='0'count_pn_enable<='1'if ok='1' thenp_state<=run_state;clr_t<='1'count_pn_enable<='0'elsif change='1' thenpass_word<=temp_password;if ok='1' thenp_state<=run_state;clr_t<='1'count_pn_enable<='0'end if;end if;when run_state=>-运行状态的处理run<='1'clr_t<='0'if ok='1' thenrun<='0'clr_cpl<='0'set_cpl<='1'p_state<=input_state;clr_t<='1'end if;end case;else-go不等于1时的处理run<='0'clr_cpl<='1'set_cpl<='0'p_state<=input_state;count_pn_enable<='0'set_count_pn<='0'end if;end if;end process;-进程名称:ok信号的控制-进程功能:通过回车键控制ok信号置1,通过clr_o置零,附去抖动process(enter,reset,clr_oo,go)beginif reset='1' thenoo<='0'elsif clr_oo='1' thenoo<='0'elsif go='1' thenif rising_edge(enter) thenoo<='1'end if;end if;end process;process(clk,clr_o,oo,count_delay1,enter)beginif rising_edge(clk) thenif go='1' thenif clr_o='1' thenok<='0'clr_o<='0'elsif oo='1' thenif count_delay1<999999 thencount_delay1<=count_delay1+1;elsif enter='1' thenok<='1'clr_o<='1'clr_oo<='1'elseok<='0'clr_o<='1'clr_oo<='1'end if;elsecount_delay1<=0;clr_o<='0'clr_oo<='0'end if;elseok<='0'clr_o<='0'clr_oo<='0'end if;end if;end process;-进程名称:complete信号的控制-进程功能:complete信号的控制process(clr_cpl,set_cpl,clk,d_complete)beginif rising_edge(clk) thenif clr_cpl='1' thencomplete<='0'elsif set_cpl='1' thencomplete<='1'else complete<=d_complete;end if;end if;end process;-进程名称:password_allow信号的控制-进程功能:password_allow信号的控制process(p_state,reset)beginif reset='1' thenpassword_allow<='0'elsif p_state=run_state thenpassword_allow<='0' ;else password_allow<='1'end if;end process;-进程名称:change信号的控制-进程功能:change信号的控制,附去抖动process(reset,change_password,clr_cc)beginif reset='1' thencc<='0'elsif clr_cc='1' thencc<='0'elsif rising_edge(change_password) thencc<='1'end if;end process;process(clk,clr_c,cc,count_delay2,change_password)beginif rising_edge(clk) thenif clr_c='1' thenchange<='0'clr_c<='0'elsif cc='1' thenif count_delay2<999999 thencount_delay2<=count_delay2+1;elsif change_password='1' thenchange<='1'clr_cc<='1'clr_c<='1'elsechange<='0'clr_cc<='1'clr_c<='1'end if;elsecount_delay2<=0;clr_cc<='0'clr_c<='0'end if;end if;end process;-进程名称:密码password的控制-进程功能:密码password的控制process(reset,pass_word)beginif reset='1' thenpassword<="0000"else password<=pass_word;end if;end process;end behavior2;-模块名称:临时密码模块-模块功能:根据数字输入模块送来的option_code产生临时密码,- 并对Unlock模块及Numeric_input模块中信号进展控制、处理。library ieee;use ieee.std_logic_1164.all;use work.My_package.all;entity Temp_password isport(reset,clk,go:in std_logic;-Unlock模块用信号password_allow :in std_logic;clr_t:in std_logic;ok:in std_logic;change:in std_logic;count_pn_enable:in std_logic;set_count_pn:in std_logic;password :in std_logic_vector(31 downto 0);temp_password:buffer std_logic_vector(31 downto 0);p_state:in state2;correct_input:out std_logic;d_complete:out std_logic;-Numeric_input模块用信号temp_no:in std_logic;option_code:in std_logic_vector(3 downto 0);d_temp_no:out std_logic;clr_temp_no:out std_logic;clr_n:out std_logic;-Display模块用信号count_pn:buffer integer -临时密码位数计数信号);end Temp_password;architecture behavior of Temp_password issignal clr_tt:std_logic:='0'-临时密码清零信号signal set_correct_input :std_logic:='0'-correct_input置位信号signal clr_count_pn :std_logic:='0'-correct_input清零信号signal set_clr_temp_no:std_logic:='0'-clr_temp_no置位信号begin-进程名称:p_state处于input_state或change_state时的数据处理-进程功能:p_state处于input_state或change_state时的数据处理process(reset,ok,clk,temp_no,go,password_allow,p_state,temp_password,password)beginif rising_edge(clk) thenif reset='1' thencorrect_input<='0'd_complete<='0'd_temp_no<='0'clr_tt<='1'elsif go='1' thenif password_allow='1' thenif ok='1' thenif p_state=input_state thenif temp_password=password thencorrect_input<='1'else d_complete<='1'clr_tt<='1'clr_count_pn<='1'end if;end if;else d_temp_no<='1'd_complete<='0'end if;elsed_temp_no<='0'correct_input<='0'd_complete<='0'clr_count_pn<='1'end if;elsecorrect_input<='0'd_complete<='0'd_temp_no<='0'clr_tt<='0'clr_count_pn<='0'end if;end if;end process;-进程名称:密码输入-进程功能:拨动开关改变临时密码并产生相应的信号处理process(clr_t,clr_tt,count_pn,temp_no,clk,go,password_allow)beginif rising_edge(clk) thenif clr_t='1' thentemp_password<="0000"elsif clr_tt='1' thentemp_password<="0000"elsif go='1' thenif password_allow='1' thenif temp_no='1' thenif count_pn<8 thentemp_password<=temp_password(27 downto 0) & option_code;set_clr_temp_no<='1'clr_n<='1'else set_clr_temp_no<='1'clr_n<='1'end if;elseset_clr_temp_no<='0'clr_n<='0'end if;elseclr_n<='1'end if;elseclr_n<='1'end if;end if;end process;-进程名称:密码输入位数处理-进程功能:密码输入位数处理,上限为八,并产生相应的信号处理process(count_pn,clr_count_pn,clk,temp_no,reset,count_pn_enable,set_count_pn)beginif rising_edge(clk) thenif reset='1' thencount_pn<=0;elsif clr_count_pn='1' thencount_pn<=0;elsif count_pn_enable='1' thenif temp_no='1' thenif count_pn<8 thencount_pn<=count_pn+1;end if;end if;elsif set_count_pn='1' thencount_pn<=9;elsecount_pn<=0;end if;end if;end process;-进程名称:clr_temp_no信号的控制-进程功能:clr_temp_no信号的控制,给clr_temp_no加一个复位process(set_clr_temp_no,reset)beginif reset='1' thenclr_temp_no<='0'elsif set_clr_temp_no='1' thenclr_temp_no<='1'else clr_temp_no<='0'end if;