EDA八位二进制密码锁

发布时间:2012-06-28 14:13:35   来源:文档文库   
字号:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity code is

port( clk: in std_logic;--电路工作时的时钟信号

clk1: in std_logic;--闹铃产生需要的时钟信号

k: in std_logic;--高电平表示输入1

led: out std_logic;--输入正确时亮

led1: out std_logic;--输入错误时亮

reset: in std_logic;-- 按下时复位

want: in std_logic;--是否修改密码

alarm: out std_logic;--输出闹铃声

show: out std_logic_vector(3 downto 0));--提示作用

end;

architecture a of code is

signal temp: std_logic_vector(3 downto 0);--输入一位加1

signal code: std_logic_vector(7 downto 0);--储存密码

signal getcode: std_logic_vector(7 downto 0);--储存修改后的密码

signal counter: std_logic_vector(3 downto 0);--计数

signal allow: std_logic;--是否允许修改密码

signal ring:std_logic;--是否接通闹铃

begin

process(clk)

begin

if ring='1' then

alarm<=clk1;--闹铃接通

else

alarm<='0';--闹铃截至

end if;

if reset='1' then--按下reset后,密码归为初始密码

getcode<="00000000";--初始密码

counter<="0000";--内部计数

code<="11001000";--密码

led<='0';

led1<='0';

allow<='0';

elsif clk'event and clk='1' then--输入clk脉冲,则接收1位密码

getcode<=getcode(6 downto 0)&k;--将这1位密码并入getcode中的最后一位

if counter="1000" then--输入为8位数码时比较

if code=getcode then

led<='1';--正确灯亮

led1<='0';

ring<='0';

allow<='1';--允许修改密码

elsif allow='1' and want='1' then--如果允许输入且想输入

code<=getcode;--输入新密码

led<='0';

led1<='0';

else

allow<='0';

led<='0';

led1<='1';--错误灯亮

ring<='1';--闹铃响

end if;

counter<="0000";--重新计数

else

counter<=counter+1; --累加

temp<=temp+1;--为防止泄露密码,特别设置

end if;

end if;

show <= temp;

end process;

end

本文来源:https://www.2haoxitong.net/k/doc/3eec4bc09ec3d5bbfd0a74f5.html

《EDA八位二进制密码锁.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式