密码锁设计VHDL源程序文档_第1页
密码锁设计VHDL源程序文档_第2页
密码锁设计VHDL源程序文档_第3页
密码锁设计VHDL源程序文档_第4页
密码锁设计VHDL源程序文档_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

2.2系统的输入、输出端口以及存放器清单及说明:CLK输入时钟方波信号端口KIN键盘按键输入端口KOUT键盘完整编码码值输出端口〔七位二进制数〕KOUT1扫描信号输出端口〔三位二进制数〕SIN键盘消抖输入端口〔七位二进制数〕SOUT键盘消抖输出端口〔七位二进制数〕LIN键盘按键编码模块输入端口〔七位二进制数〕DF数字按键标志存放器FF功能按键标志存放器ND数字按键识别编码存放器NF功能按键识别编码存放器LOCK电子密码锁上锁状态标志存放器LOCK1电子密码锁报警状态标志存放器UNLOCK电子密码锁开锁状态标志存放器NULL1电子密码锁无密码状态标志存放器DATA电子密码锁数码显示数据存放器CAT电子密码锁数码显示位选存放器DISPLAY电子密码锁数码显示段选存放器〔十七位二进制数〕NUM0、NUM1、NUM2、NUM3数码显示中分位显示数据存放器DISNUM数码显示段选数据存放器I1数码显示计数器SCANS键盘扫描中按键完整编码存放器SCAN键盘扫描存放器CNT键盘消抖计数器SIN1键盘按键键值存放器I键盘扫描计数器DF1数字按键状态标志存放器ACC键盘数字输入暂存器T报警计数器REG电子密码锁密码存储器NC计数器1键盘输入扫描局部源程序LIBRARYIEEE;USEIEEE.STD_LOGIC_ARITH.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_1164.ALL;ENTITYkbscan1isPORT(clk:inSTD_LOGIC;kin:inSTD_LOGIC_VECTOR(3DOWNTO0);---PC7-PC4kout:outSTD_LOGIC_VECTOR(7downto0);--PC3--PCkout1:outSTD_LOGIC_VECTOR(3downto0));endkbscan1;architectureaofkbscan1issignalscans:std_logic_vector(7downto0);--PC7--PC0signalscan:std_logic_vector(3downto0);--PC3--PC0signalcnt:integerrange0to140;signalsin1:std_logic_vector(3downto0);signali:integerrange0to3;beginscans<=scan&kin;kout<=scans;kout1<=scan;process(clk)beginif(falling_edge(clk))thenif(i=3)theni<=0;elsei<=i+1;endif;caseiiswhen0=>scan<="0001";when1=>scan<="0010";when2=>scan<="0100";when3=>scan<="1000";endcase;endif;endprocess;Enda;2键盘输入消抖局部源程序LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYxiaodouisPort(clk:inSTD_LOGIC;sin:instd_logic_vector(7downto0);sout:outstd_logic_vector(7downto0));endxiaodou;architecturebehavioralofxiaodouissignalcnt:integerrange0to120;signalsin1:std_logic_vector(7downto0);beginprocess(clk)beginsin1<=sin;if(rising_edge(clk))thenif(sin1=sin)thencnt<=cnt+1;elsesin1<=sin;cnt<=0;endif;if(cnt=120)thensout<=sin;cnt<=0;endif;endif;endprocess;endbehavioral;3键盘输入编码局部源程序LIBRARYIEEE;USEIEEE.STD_LOGIC_ARITH.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_1164.ALL;ENTITYbianmaisPORT(clk:inSTD_LOGIC;lin:inSTD_LOGIC_VECTOR(7DOWNTO0);---PC7-PC4DF,FF:outstd_logic;nd,nf:BUFFERstd_logic_vector(3downto0));endbianma;architecturebofbianmaisbeginprocess(clk)beginifclk'eventandclk='1'thencaseliniswhen"10000001"=>ND<="0000";--0when"00010001"=>ND<="0001";--1when"00010010"=>ND<="0010";--2when"00010100"=>ND<="0011";--3when"00100001"=>ND<="0100";--4when"00100010"=>ND<="0101";--5when"00100100"=>ND<="0110";--6when"01000001"=>ND<="0111";--7when"01000010"=>ND<="1000";--8when"01000100"=>ND<="1001";--9whenothers=>ND<="1111";ENDCASE;ENDIF;IFCLK'EVENTANDCLK='1'THENCASELINISwhen"00011000"=>NF<="0001";--qingchuwhen"00101000"=>NF<="0010";--querenwhen"01001000"=>NF<="0011";--shangsuowhen"10001000"=>NF<="0100";--kaisuowhen"10000100"=>NF<="0101";--wangjimimawhen"10000010"=>NF<="0111";--genggaimimaWhenothers=>NF<="1000";ENDCASE;ENDIF;ENDPROCESS;DF<=NOT(ND(3)ANDND(2)ANDND(1)ANDND(0));FF<=NF(2)ORNF(1)ORNF(0);endb;4电子密码锁的控制局部程序DF数字按键标志存放器FF功能按键标志存放器ND数字按键识别编码存放器NF功能按键识别编码存放器LOCK电子密码锁上锁状态标志存放器LOCK1电子密码锁报警状态标志存放器UNLOCK电子密码锁开锁状态标志存放器NULL1电子密码锁无密码状态标志存放器DATA电子密码锁数码显示数据存放器LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYkongzhiISPORT(CLK:INSTD_LOGIC;DF,FF:inSTD_LOGIC;ND,NF:inSTD_LOGIC_VECTOR(3downTO0);LOCK,LOCK1,UNLOCK:bufferSTD_LOGIC;NULL1:bufferSTD_LOGIC;DATA:outSTD_LOGIC_VECTOR(15downTO0));ENDkongzhi;ARCHITECTUREV1OFkongzhiISsignali1:integerrange0to3;signaldf1:std_logic;signalACC:STD_LOGIC_VECTOR(15DOWNTO0);signalt:INTEGERsignalREG:STD_LOGIC_VECTOR(15downTO0);signalNC,A:INTEGERbeginPROCESS(FF,DF)ISBEGINifrising_edge(clk)thenIFFF='1'THENIFNF="0001"THENACC<="0000000000000000";NC<=0;ENDIF;ELSEdf1<=df;IFdf1='0'andDF='1'THENIFNC<4THENACC<=ACC(11DOWNTO0)&ND;NC<=NC+1;ENDIF;ENDIF;ENDIF;IFFF='1'THENIFNF="0011"THENREG<=ACC;LOCK<='0';UNLOCK<='1';LOCK1<='1';NULL1<='1';elseIFNF="0100"THENIFREG=ACCTHENLOCK<='1';UNLOCK<='0';LOCK1<='1';NULL1<='1';ELSELOCK<='0';UNLOCK<='1';IFt=2THENLOCK1<='0';lock<='1';unlock<='1';null1<='1';t<=0;ELSEt<=t+1;ENDIF;ENDIF;elseIFNF="0101"THENLOCK<='0';UNLOCK<='1';LOCK1<='1';NULL1<='1';elseIFNF="0111"THENIFUNLOCK='1'THENIFREG=ACCTHENREG<="0000000000000000";NULL1<='0';LOCK<='1';LOCK1<='1';UNLOCK<='1';ENDIF;ENDIF;elseIFNF="0010"THENREG<=ACC;NULL1<='1';LOCK<='0';LOCK1<='1';UNLOCK<='1';ENDIF;endif;endif;endif;endif;endif;endif;ENDPROCESS;DATA<=ACC;ENDARCHITECTUREV1;CAT电子密码锁数码显示位选存放器DISPLAY电子密码锁数码显示段选存放器〔十七位二进制数〕DISPLAY电子密码锁数码显示段选存放器〔十七位二进制数〕NUM0、NUM1、NUM2、NUM3数码显示中分位显示数据存放器DISNUM数码显示段选数据存放器I1数码显示计数器5电子密码锁的数码显示模块源程序LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYLEDXIANSHIISPORT(CLK:INSTD_LOGIC;DATA:inSTD_LOGIC_VECTOR(15DOWNTO0);CAT:OUTSTD_LOGIC_VECTOR(0TO3);DISPLAY:OUTSTD_LOGIC_VECTOR(16DOWNTO0));ENDLEDXIANSHI;ARCHITECTUREBEHAVIORALOFLEDXIANSHIISSignalNUM0,NUM1,NUM2,NUM3:STD_LOGIC_VECTOR(3DOWNTO0);SIGNALDISNUM:STD_LOGIC_VECTOR(16DOWNTO0);SIGNALI1:INTEGERBEGINNUM0<=DATA(3DOWNTO0);NUM1<=DATA(7DOWNTO4);NUM2<=DATA(11DOWNTO8);NUM3<=DATA(15DOWNTO12);DISPLAY<=DISNUM;PROCESS(CLK)BEGINIF(RISING_EDGE(CLK))THENIF(I1=3)THENI1<=0;ELSEI1<=I1+1;ENDIF;ENDIF;ENDPROCESS;PROCESS(I1)BEGINCASEI1ISWHEN0=>CAT<="1110";CASENUM0ISWHEN"0000"=>DISNUM<="00000000011111111";WHEN"0001"=>DISNUM<="00000000000001100";WHEN"0111"=>DISNUM<="00000000000001111";WHENOTHERS=>DISNUM<=NULL;ENDCASE;WHEN1=>CAT<="1101";CASENUM1ISWHEN"0000"=>DISNUM<="00000000011111111";WHEN"0001"=>DISNUM<="00000000000001100";WHEN"0111"=>DISNUM<="00000000000001111";WHENOTHERS=>DISNUM<=NULL;ENDCASE;WHEN2=>CAT<="1011";CASENUM2ISWHEN"0000"=>DISNUM<="00000000011111111";WHEN"0001"=>DISNUM<="00000000000001100";WHEN"0111"=>DISNUM<="00000000000001111";WHENOTHERS=>DISNUM<=NULL;ENDCASE;WHEN3=>CAT<="0111";CASENUM3ISWHEN"0000"=>DISNUM<="00000000011111111";WHEN"0001"=>DISNUM<="00000000000001100";WHEN"0111"=>DISNUM<="00000000000001111";WHENOTHERS=>DISNUM<=NULL;ENDCASE;ENDCASE;ENDPROCESS;ENDBEHAVIORAL;6电子密码锁的数码显示局部〔附加〕LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYLEDXIANSHIISPORT(CLK:INSTD_LOGIC;DATA:inSTD_LOGIC_VECTOR(15DOWNTO0);CAT:OUTSTD_LOGIC_VECTOR(0TO3);DISPLAY:OUTSTD_LOGIC_VECTOR(16DOWNTO0));ENDLEDXIANSHI;ARCHITECTUREBEHAVIORALOFLEDXIANSHIISsignalNUM0,NUM1,NUM2,NUM3:STD_LOGIC_VECTOR(3DOWNTO0);SIGNALDISNUM:STD_LOGIC_VECTOR(16DOWNTO0);SIGNALI1:INTEGERBEGINNUM0<=DATA(3DOWNTO0);NUM1<=DATA(7DOWNTO4);NUM2<=DATA(11DOWNTO8);NUM3<=DATA(15DOWNTO12);DISPLAY<=DISNUM;PROCESS(CLK)BEGINIF(RISING_EDGE(CLK))THENIF(I1=3)THENI1<=0;ELSEI1<=I1+1;ENDIF;ENDIF;ENDPROCESS;PROCESS(I1)BEGINCASEI1ISWHEN0=>CAT<="1110";CASENUM0ISWHEN"0000"=>DISNUM<="00000000011111111";ENDCASE;WHEN1=>CAT<="1101";CASENUM1ISWHEN"0000"=>DISNUM<="00000000011111111";ENDCASE;WHEN2=>CAT<="1011";CASENUM2ISWHEN"0000"=>DISNUM<="00000000011111111";ENDCASE;WHEN3=>CAT<="0111";CASENUM3ISWHEN"0000"=>DISNUM<="00000000011111111";ENDCASE;ENDCASE;ENDPROCESS;ENDBEHAVIORAL;数码管显示libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityKeyScanis port( RESET : in std_logic; CLK : in std_logic; --根本时钟源6MHz KeyIn : in std_logic_vector(3downto0); --column列 KeyOut : out std_logic_vector(3downto0);--row行 LED_A : outstd_logic; --4位数码管引脚 LED_B : outstd_logic; LED_C : outstd_logic; LED_D : outstd_logic; LED_E : outstd_logic; LED_F : outstd_logic; LED_G : outstd_logic; LED_VCC1 : outstd_logic; --时十位 LED_VCC2 : outstd_logic; --时个位 LED_VCC3 : outstd_logic; --分十位 LED_VCC4 : outstd_logic; --分个位 LED_TimePoint:outstd_logic; --冒号 LED_Point :outstd_logic;--小数点 LED_EN1 :outstd_logic--小数点 );endKeyScan;architectureBehavioralofKeyScanis signaltimecnt : integerrange0to100000 ;--分频计数器,用来得到10ms时钟 signaltime10ms : std_logic ; --10ms时钟 signalscanvalue:std_logic_vector(3downto0);--记录扫描数据 signalcombvalue:std_logic_vector(7downto0);--KeyIn、KeyOut组合值 signalcpy_scanvalue:std_logic_vector(3downto0);--备份扫描数据 signalcount : integerrange0to60000 ; --分频器,产生毫秒时钟基准 signalscancnt : integerrange0to3 ; --LED扫描轮转 signalData0: integerrange0to9 ; begin LED_EN1<='0'; --进程1:产生20ms时钟 process(CLK,RESET) begin ifRESET='0'then time10ms<='0'; --初始化 elsifCLK'eventandCLK='1'then timecnt<=timecnt+1; iftimecnt=100000 thentime10ms<=nottime10ms;timecnt<=0; endif; endif; endprocess; --进程2:键盘扫描输出 process(time10ms,RESET) begin ifRESET='0'then scanvalue<="0001";combvalue<="00000000"; Data0<=0; --初始化 elsiftime10ms'eventandtime10ms='1'then --每10ms进行一次键盘扫描 KeyOut<=scanvalue;--输出扫描值 cpy_scanvalue<=scanvalue; --备份扫描值,为了进程3对扫描结果进行比拟 casescanvalueis --扫描值移位 when"0001"=>scanvalue<="0010"; when"0010"=>scanvalue<="0100"; when"0100"=>scanvalue<="1000"; when"1000"=>scanvalue<="0001"; whenothers=>scanvalue<="0001"; endcase; combvalue<=(KeyIn&cpy_scanvalue);--组合键盘扫描的输入和输出 casecombvalueis --翻译扫描结果 when"00010001"=>Data0<=1;--对应键盘“1〞 when"00100001"=>Data0<=2;--对应键盘“2〞 when"01000001"=>Data0<=3;--对应键盘“3〞 when"00010010"=>Data0<=4;--对应键盘“4〞 when"00100010"=>Data0<=5;--对应键盘“5〞 when"01000010"=>Data0<=6;--对应键盘“6〞 when"00010100"=>Data0<=7;--对应键盘“7〞 when"00100100"=>Data0<=8;--对应键盘“8〞 when"01000100"=>Data0<=9;--对应键盘“9〞 when"00011000"=>Data0<=0;--对应键盘“0〞 whenothers=>null;--无键盘按下 endcase; endif; endprocess;--数码管扫描process(CLK,RESET) --时钟进程,产生各种时钟信号 begin ifRESET='0'then NULL; elsifCLK'eventandCLK='1'then count<=count+1; ifcount=60000then count<=0; ifscancnt>3thenscancnt<=0; else scancnt<=scancnt+1; endif; endif; endif; endprocess; --数码管扫描process(CLK,RESET) begin --LED_VCC信号是‘1’有效,其余信号均为‘0’有效,中间的冒号两个点分别由VCC2和VCC3控制 ifRESET='0'then LED_A<='1';LED_B<='1'; LED_C<='1';LED_D<='1';LED_E<='1';LED_F<='1';LED_G<='1';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='0';LED_TimePoint<='1'; LED_Point<='1'; else ifscancnt=0then caseData0is --分个位 when0=>LED_A<='0';LED_B<='0'; LED_C<='0';LED_D<='0';LED_E<='0';LED_F<='0';LED_G<='1';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when1=>LED_A<='1';LED_B<='0'; LED_C<='0';LED_D<='1';LED_E<='1';LED_F<='1';LED_G<='1';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when2=>LED_A<='0';LED_B<='0'; LED_C<='1';LED_D<='0';LED_E<='0';LED_F<='1';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when3=>LED_A<='0';LED_B<='0'; LED_C<='0';LED_D<='0';LED_E<='1';LED_F<='1';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when4=>LED_A<='1';LED_B<='0'; LED_C<='0';LED_D<='1';LED_E<='1';LED_F<='0';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when5=>LED_A<='0';LED_B<='1'; LED_C<='0';LED_D<='0';LED_E<='1';LED_F<='0';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when6=>LED_A<='0';LED_B<='1'; LED_C<='0';LED_D<='0';LED_E<='0';LED_F<='0';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when7=>LED_A<='0';LED_B<='0'; LED_C<='0';LED_D<='1';LED_E<='1';LED_F<='1';LED_G<='1';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when8=>LED_A<='0';LED_B<='0'; LED_C<='0';LED_D<='0';LED_E<='0';LED_F<='0';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; when9=>LED_A<='0';LED_B<='0'; LED_C<='0';LED_D<='0';LED_E<='1';LED_F<='0';LED_G<='0';LED_VCC1<='0';LED_VCC2<='0';LED_VCC3<='0';LED_VCC4<='1';LED_Point<='1'; whenothers=>null; endcase; endif; endif;endprocess;endBehavioral;控制电路的软件仿真图〔1〕图2-11控制电路的软件仿真图〔2〕控制电路的软件仿真图〔3〕控制电路的软件仿真图〔4〕控制电路的软件仿真图〔5〕5电子密码锁的数码显示模块源程序〔改七段〕LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYLEDXIANSHIISPORT(CLK:INSTD_LOGIC;LED_TimePoint:outstd_logic; --冒号 LED_Point :outstd_logic;--小数点 LED_EN1 :outstd_logic;--选择数码管显示DATA:inSTD_LOGIC_VECTOR(15DOWNTO0);CAT:OUTSTD_LOGIC_VECTOR(0TO3);DISPLAY:OUTSTD_LOGIC_VECTOR(6DOWNTO0));ENDLEDXIANSHI;ARCHITECTUREBEHAVIORALOFLEDXIANSHIISSignalNUM0,NUM1,NUM2,NUM3:STD_LOGIC_VECTOR(3DOWNTO0);SIGNALDISNUM:STD_LOGIC_VECTOR(6DOWNTO0);SIGNALI1:INTEGERBEGINNUM0<=DATA(3DOWNTO0);NUM1<=DATA(7DOWNTO4);NUM2<=DATA(11DOWNTO8);NUM3<=DATA(15DOWNTO12);DISPLAY<=DISNUM;PROCESS(CLK)BEGINIF(RISING_EDGE(CLK))THENIF(I1=3)THENI1<=0;ELSEI1<=I1+1;ENDIF;ENDIF;ENDPROCESS;PROCESS(I1)BEGINCASEI1ISWHEN0=>CAT<="0001";CASENUM0ISWHEN"0000"=>DISNUM<="1000000";WHEN"0001"=>DISNUM<="1111001";WHEN"0010"=>DISNUM<="0100100";WHEN"0011"=>DISNUM<="0110000";WHEN"0100"=>DISNUM<="0011001";WHEN"0101"=>DISNUM<="0010010";WHE

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论