集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1573|回复: 1

数字锁的VHDL实现

[复制链接]
伯尼 发表于 2011-5-20 16:04:25 | 显示全部楼层 |阅读模式
--设计一个三位数的电子密码锁,通过输入的数字控制密码锁的开关。
--开锁器件用户可通过change键自行设置密码;
--开锁时,先输入密码,按下test键检测,密码正确时开锁:输出lockopen为高电平,lockclose
--为低电平,密码锁开启;否则lockopen为低电平,lockclose为高电平,密码锁关闭;
--lockopen和lockclose分别用来驱动绿色和红色发光二极管,作为密码锁的状态显示;
--任何状态下输入的三位数字将在七段共阴极数码管显示。

--主控制模块
library ieee;
use ieee.std_logic_1164.all;
entity lock is
port(numh,numt,numo:in std_logic_vector(9 downto 0);--百十个位数输入
         displayh,displayt,displayout std_logic_vector(6 downto 0);--数码管驱动百十个位数
         clk:in std_logic;
         change,test:in std_logic;--密码设定和密码检测
         lockopen,lockcloseut std_logic--开锁和关锁信号
        );
end lock;

architecture rt1 of lock is
component decoder is
        port(
                clk:in std_logic;
                data:in std_logic_vector(9 downto 0);
                qut std_logic_vector(6 downto 0);   --七位数码管驱动
                q1ut std_logic_vector(3 downto 0)   --数值译码
                );
end component;
signal enable ,c0,c1,s,enable1:std_logic;
signal temph,tempt,tempo,deco_h,deco_t,deco_o:std_logic_vector(3 downto 0);
begin
        enable<=change and (not test);
        enable1<=test and (not change);
u0:decoder
        port map(clk=>clk,data=>numh,q=>displayh,q1=>deco_h); --百位输入译码
u1:decoder
        port map(clk=>clk,data=>numt,q=>displayt,q1=>deco_t); --十位输入译码
u2:decoder
        port map(clk=>clk,data=>numo,q=>displayo,q1=>deco_o);--个位输入译码

        process(clk,deco_h,deco_t,deco_o)
begin
        if rising_edge(clk) then
                if enable='1' then
                        temph<=deco_h;
                        tempt<=deco_t;
                        tempo<=deco_o;
                end if ;
                if enable1='1' then
                        if temph=deco_h and tempt=deco_t and tempo=deco_o then
                                lockopen<='1';
                                lockclose<='0';
                        else
                                lockopen<='0';
                                lockclose<='1';
                        end if;
                end if;
        end if;
        end process;
end rt1;

       



--输入译码模块
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
port(
        clk:in std_logic;
        data:in std_logic_vector(9 downto 0);
        qut std_logic_vector(6 downto 0);
        q1ut std_logic_vector(3 downto 0)
        );
end decoder;

architecture rt1 of decoder is
begin
        process(clk,data)
        begin
                if rising_edge(clk) then
                case data is
                        when "0000000000"=>q<="0110000";q1<="0000";
                        when "0000000001"=>q<="0110000";q1<="0000";
                        when "0000000010"=>q<="0111111";q1<="0001";
                        when "0000000100"=>q<="1101101";q1<="0010";
                        when "0000001000"=>q<="1111001";q1<="0011";
                        when "0000010000"=>q<="0110011";q1<="0100";
                        when "0000100000"=>q<="1011011";q1<="0101";
                        when "0001000000"=>q<="0011111";q1<="0110";
                        when "0010000000"=>q<="1110000";q1<="0111";
                        when "0100000000"=>q<="1111111";q1<="1000";
                        when "1000000000"=>q<="1110011";q1<="1001";
                        when others=>q<="0000000";q1<="0000";
                end case;
        end if;
        end process;
end rt1;
 楼主| 伯尼 发表于 2011-5-21 18:06:41 | 显示全部楼层
怎么出现了小人头?
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-17 19:47 , Processed in 0.141781 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表