电子设计自动化技术实训 CSH 16
课题5 密码锁
一、 设计任务及要求
设计一个两位的密码锁,要求如下:
1. 开锁代码为2位十进制并行码。
2. 当输入的密码与锁内的密码一致时,绿灯亮,开锁;当输入的密码与锁内
的密码不一致时,红灯亮,不能开锁。 3. 密码可由用户自行设置。
二、 可选器件
EPM130208-2、共阴极七段数码管、发光二极管、按键开关、电阻、电容。
三、 设计总体框图
密码锁总体框图如图5所示
译 码 显 示 数 据 输 入 数 据 寄 存 判 断 开 锁 CN 图5 密码锁总体框图
密 码 检 测 C 密 码 存储指 示 灯 指 示 灯
四、 源程序
library ieee;
use ieee.std_logic_signed.all; entity lock is
port(a:in std_logic_vector(9downto0);——十位输入端。 B:in std_logic_vector(9downto0);——个位输入端。 En,clk:in std_logic;——en为密码确认开关。 En1:in std_logic;——en1为密码检验开关。
C,d:out std_logic_vector(6downto0):=”0111111”;——输出七段数码管的控制。 K,m:out std_logic);——K为绿灯,M为红灯。 End lock;
Architecture behave of lock is
电子设计自动化技术实训 CSH
Signal e:std_logic_vector(3downto0); Signal f: std_logic_vector (3downto0); Signal g:std_logic_vector(3downto0); Signal h:std_logic_vector(3downto0); Signal count1,count2,:std_logic:=’0’’ Signal s:std_logic:=’0’; Begin
If (a(9downto0)=”0000000000”) Then c(6downto0)<=”0111111”; Elsif (a(1)=’1’) then
E<=”0000”;c(6downto0)<=”0111111”; Elsif(a(1)=’1’)then
E<=”0001”;c(6downto0)<=”0000110”; Elsif(a(2)=’1’)then
E<=”0010”;c(6downto0)<=”1011011”; Elsif(a(3)=’1’)then
E<=”0011”;c(6downto0)<=”1001111”; Elsif (a(4)=’1’) then
E<=”0100”;c(6downto0)<=”1100110”; Elsif (a(5)=’1’) then
E<=”0101”;c(6downto0)<=”1101101”; Elsif(a(6)=’1’) then
E<=”0110”;c(6downto0)<=”1111100”; Elsif(a(7)=’1’) then
E<=”0111”;c(6downto0)<=”0000111”; Elsif(a(8)=’1’) then
E<=”1000”;c(6downto0)<=”1111111”; Elsif(a(9)=’1’)) then
E<=”1001”;c(6downto0)<=”1100111”; End if; End process;
Process(b,f)——个位的数据转换。 Begin
If(b(9downto0)=”00000000000” then D(6downto0)<=”0111111”; Elsif(b(0)=’1’) then
F<=”0000”;d(6downto0)<=”0111111”; Elsif(b(1)=’1’)then
F<=”0001”;d(6downto0)<=0000100”; Elsif(b(2)=’1’;then
17
电子设计自动化技术实训 CSH
F<=”0010”;d(6downto0)<=”1011011”; Elsif(b(3)=’1’) then
F<=”0011”;d(6downto0)<=”1001111”; Elsif(b(4)=’1’) then
F<=”0100”;d(6downto0)<=”1100110”; Elsif(b(5)=’1’) then
F<=”0101”;d(6downto0)<=”1101101”; Elsif(b(6)=’1’) then
F<=”0110”; d(downto0)<=”1111100”; Elsif(b(7)=’1’)then
F<=”0111”;d(6downto0)<=”0000111”; Elsif(b(8)=’1’) then
F<=”1000”;d(6downto0)<=”1111111”; Elsif(b(9)=’1’) then
F<=”1001”;d(6downto0)<=”1100111”; End if; End process;
Process(clk)——判断密码是否正确,可否开锁。 Begin
If(s=’1’)and(en=’1’)and(count=’0’) then G(3downto0)<=e(3downto0); H(3downto0)<=F(3downto0); Count1<=not(count1); End if;
If(en1=’1’)and(count2=’0’) then
If(e(3downto0)=g(3downto0)andf(3downto0)=h(3downto0)) then K<=’1’; S<=’1’; Else K<=’0’; M<=’1’; End if;
If (en=’0’)and(en1=’0’) then Count1<=’0’; Count2<=’0’; K<=’0’;s<=’0’;m<=’0’; End if;
If(en=’0’ and s=’1’) then Count1<=’0’; End if;
18
电子设计自动化技术实训 CSH
End process; End behave;
19
五、 程序说明
1. 此程序由解码、译码、数码管显示部分组成。
2. 此程序是一个并行密码锁,用户开锁密码为00。当使用开锁密码后,指示
灯亮(绿灯),表示锁被打开。用户可自行设置密码。
用户可用2个DIP开关(1—10)设置0—99的2位十进制数密码。
电子设计自动化技术实训 CSH 20
课题6 数字频率计
一、 设计任务及要求
设计一个4位十进制数字显示的数字式频率计。要求如下:
1. 4位十进制数字显示的数字显示的数字式频率计,其频率测量范围为
10~9999kHZ,测量单位为kHZ。 2. 要求量程能够自动转换。(即测几十到几百千赫兹(kHZ)时,有小数点显示,
前者显示小数点后两位,后者显示小数点后一位。)
3. 当输入的信号小于10kHZ时,输出显示全0;当输入的信号大于9999kHZ时,
输出显示全H。
二、 可选器件
EPM130208-2、共阴极七段数码管、按键开关、电阻、电容。
三、 设计总体框图
数字频率计总体框图如图6所示。
复位
被测信号 计数电路 锁存器 时分复用 译码显 示
时钟输 入 分频电 路 图6 数字频率计总体框图
四、 源程序
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; entity total is
port (cp_20m:in std_logic; enable:in std_logic;