完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
LIBRARY IEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;ENtiTY LOCK ISPORT(CLK,CLK5:INSTD_LOGIC; KEY1,KEY2,KEY3,KEY4,KEY5,KEY6,KEY7,KEY8:INSTD_LOGIC; Q1,Q2,Q3,Q4:OUT STD_LOGIC_VECTOR(3 DOWNTO0); LED_G,LED_R,LED,BEEP:OUT STD_LOGIC);END LOCK;ARCHITECTURE BEHAVOF LOCK IS SIGNAL PASSWORD1:STD_LOGIC_VECTOR(3 DOWNTO0):="0001"; SIGNAL PASSWORD2:STD_LOGIC_VECTOR(3 DOWNTO0):="0001"; SIGNAL PASSWORD3:STD_LOGIC_VECTOR(3 DOWNTO0):="0001"; SIGNAL PASSWORD4:STD_LOGIC_VECTOR(3 DOWNTO0):="0001"; SIGNAL JISHI5:STD_LOGIC_VECTOR(3 DOWNTO0):="0000"; SIGNAL JISHI20:STD_LOGIC_VECTOR(4 DOWNTO0):="00000"; SIGNALZISUO,FLAG,BEEP_FLAG,KAI,LED_TMP:STD_LOGIC:='0'; SIGNALCODE1,CODE2,CODE3,CODE4:STD_LOGIC_VECTOR(3 DOWNTO 0); BEGIN PROCESS(clk,key1,key2,key3,key4,key6)BEGINIF ZISUO='0' ANDKEY6='0' AND KAI='0' THEN IF KEY1'EVENT AND KEY1='1' THEN --用来输入代码,在关锁状况下,并且无开锁和设置密码信号下有效 IF CODE1<9 THENCODE1<=CODE1+1; ELSE CODE1<=(OTHERS=>'0'); END IF; END IF; IF KEY2'EVENT AND KEY2='1' THEN IF CODE2<9 THEN CODE2<=CODE2+1; ELSE CODE2<=(OTHERS=>'0'); END IF; END IF; IF KEY3'EVENT AND KEY3='1' THEN IF CODE3<9 THENCODE3<=CODE3+1; ELSE CODE3<=(OTHERS=>'0'); END IF; END IF; IF KEY4'EVENT AND KEY4='1' THEN IF CODE4<9 THENCODE4<=CODE4+1; ELSE CODE4<=(OTHERS=>'0'); END IF; END IF; ELSIF(ZISUO='0' AND KEY7='1' AND KAI='1')THEN CODE1<="0000";CODE2<="0000";CODE3<="0000";CODE4<="0000";--这一步很重要,重新上锁必须将密码值清零,不然会显示上次输入的密码 IF KEY6='1' AND KAI='1' THEN --显示密码 Q1<=PASSWORD1; Q2<=PASSWORD2; Q3<=PASSWORD3; Q4<=PASSWORD4; END IF; IF KEY6='0' AND KAI='0' THEN --显示要更改的密码 Q1<=CODE1; Q2<=CODE2; Q3<=CODE3; Q4<=CODE4; END IF; IF KEY6='0' AND KAI='1' THEN --开锁后显示零 Q1<="0000"; Q2<="0000"; Q3<="0000"; Q4<="0000"; END IF; ELSIF ZISUO='0' AND KEY6='1' AND KAI='1'THEN --按住KEY6设置密码,此时必须是开锁状态 IF KEY1'EVENT AND KEY1='1' THEN IF PASSWORD1<9 THENPASSWORD1<=PASSWORD1+1; ELSE PASSWORD1<=(OTHERS=>'0'); END IF; END IF; IF KEY2'EVENT AND KEY2='1' THEN IF PASSWORD2<9 THENPASSWORD2<=PASSWORD2+1; ELSE PASSWORD2<=(OTHERS=>'0'); END IF; END IF; IF KEY3'EVENT AND KEY3='1' THEN IF PASSWORD3<9 THENPASSWORD3<=PASSWORD3+1; ELSE PASSWORD3<=(OTHERS=>'0'); END IF; END IF; IF KEY4'EVENT AND KEY4='1' THEN IF PASSWORD4<9 THENPASSWORD4<=PASSWORD4+1; ELSE PASSWORD4<=(OTHERS=>'0'); End IF; END IF; END IF; END PROCESS; PROCESS (CLK,key5,key7) BEGIN IF CLK'EVENT AND CLK='1' THEN IF KEY5='1' AND ZISUO='0' AND KEY6='0'THEN IF PASSWORD1=CODE1 AND PASSWORD2=CODE2 ANDPASSWORD3=CODE3 AND PASSWORD4=CODE4 THEN KAI<='1'; --按下开锁键后,如果密码正确,开锁 ELSE KAI<='0'; END IF; END IF; END IF; IF KAI='1' THEN LED_G<='1';LED_R<='0'; --开锁后红灯灭绿灯亮,否则红灯亮绿灯灭 ELSE LED_G<='0';LED_R<='1'; END IF; IF KEY7='1' AND KEY6='0' THEN --关锁按钮按下后关锁 KAI<='0';LED_G<='0';LED_R<='1'; END IF; END PROCESS; PROCESS(CLK,KEY1,KEY8) BEGIN IF(KEY1'EVENT AND KEY1='1')THEN FLAG<='1'; END IF; IF CLK'EVENT AND CLK='1' THEN --按下第一个按键时 置位标志位FLAG,开始计时 IF(FLAG='1')THEN IF ZISUO='0' AND KEY6='0' ANDKAI='0' THEN IF JISHI5<5 THENJISHI5<=JISHI5+1; ELSE JISHI5<="0000"; END IF; END IF; END IF; IF (JISHI5=5 AND KAI='0') THEN --如果5秒后未开锁则进入自锁状态 ZISUO<='1'; END IF; END IF; IF KAI='1' THEN --5秒内开锁 计时清零,标志位清零 JISHI5<="0000";FLAG<='0'; END IF; IF KEY8='1' AND ZISUO='1' THEN --K8按下后清除自锁 ZISUO<='0';FLAG<='0'; END IF; END PROCESS; PROCESS(CLK,KEY8,CLK5) BEGIN IF CLK'EVENT AND CLK='1' THEN --如果自锁则蜂鸣器持续20秒发声 IF ZISUO='1' THEN IF JISHI20<20 THEN JISHI20<=JISHI20+1; BEEP_FLAG<='1'; --置位蜂鸣器标志位 ELSE BEEP_FLAG<='0'; END IF; LED_TMP<=NOT LED_TMP; --进入自锁后灯闪烁提示 LED<=LED_TMP; END IF; IF ZISUO='0' THEN --自锁解除,清零计时值和标志位 JISHI20<="00000";LED<='0';BEEP_FLAG<='0';LED_TMP<='0';JISHI20<="00000"; END IF; END IF; IFBEEP_FLAG='1' THEN --判断蜂鸣器标志位是否为1 IF CLK5='1' THEN --CLK5给无源蜂鸣器提供1K的时钟信号 BEEP<='1'; ELSE BEEP<='0'; END IF; END IF;END PROCESS;END BEHAV;
|
|
相关推荐
1个回答
|
|
语法结构的差异比较大,要重新按逻辑进行编写
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1307 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1038 浏览 0 评论
2382 浏览 1 评论
2087 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2349 浏览 0 评论
1868 浏览 49 评论
6007 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 20:05 , Processed in 0.591443 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号