数电实验大作业2-实验十一 电子密码锁

 

实验要求..在下面这个链接里:

http://docs.google.com/fileview?id=0B_IAvxLi-MonMjhmMDM5OTgtNzgyMC00MTMwLWJiNGItMmUxODQ4MGY2ZmUz&hl=zh_CN

 

完整的实验报告:

1. 电子锁功能要求

l 2种工作模式,可以设置和校验密码

l 密码长度为8位,内容为数字1-9,分别对应9个微动开关

l 8个数码管实时显示当前输入的密码值

l 密码校验正确则点阵显示为绿色的”OK”,同时播放一种音乐

l 密码校验错误则点阵显示为红色的”NO”,同时播放另一种音乐

2. 需求分析与系统设计

l 密码有8位,且每位的内容为数字1-9

l 需要一个4位的寄存器来存储一个密码位的值,总共需要8个寄存器来存储一个密码.

l 再有一个比较模块来比较2个存储模块中存储的密码是否相同.

l 点阵与蜂鸣器根据比较结果来做出相应的输出

l 数码管实时显示当前存储器中的各位密码值

3. 各模块具体设计

1) 密码存储模块

Data[3..0]为一位密码的输入端口,由clk[8..1]中的有效位来控制将该位密码存入某个寄存器中,s1[3..0]~s8[3..0]为各位寄存器的状态输出端口,可用来获得各位密码的值.

在本系统中总共需要2个这样的寄存模块,一个用来存放设置的原密码,另一个用来存放用户验证时输入的密码.然后只要比较这两个寄存模块的值就可确定密码是否输入正确了.

2) 获得键盘值模块

根据9个针脚上连接的按键的响应情况来转码输出对应的密码值

3) 主要逻辑控制模块

• 根据拨码开关状态来控制设置或者校验密码这2种工作方式

• 将按键输入的各个密码值送到各自的存储器中存储

• 发出密码输入完毕开始校验的状态

4) 点阵显示模块

根据main的指令来控制点阵显示相应的内容.

5) 数码管显示模块

根据main指令选择不同的存储器,实时显示密码值到数码管上.

6) 音频播放模块

将验证的结果的正确与否使用不同的曲子来表示

若结果正确,播放一段升音阶的旋律

若不正确,播放一段降音阶的旋律

7) 其他模块

有了上述这6个主要的功能模块后,还需要配合一些基本的小模块来完成实验.比如需要一个按键消抖的模块来准确的获得按键值.需要一个七段数码管模块来输出显示信号.需要一个22位的计数器来进行分频等.

4. 系统顶层图

5. 实验中碰到的问题及解决方案

l 点阵与led的显示出现非预设的结果.原因是clk频率太高,由于人的视觉残留等原因造成错觉.降低了显示的刷新频率后解决

l 按键的消抖做的不好,还是有误按.逐步调试,慢慢降低了键盘检测的频率(等于是使键盘响应变迟钝)后解决.目前高速击键都可以被正常识别,没有错误现象了

6. 实验心得

这个实验应该是综合率比较高的了.把2种按键输入,点阵,数码管和蜂鸣器这3种输出以及存储器的读写功能都实现了.通过这个实验可以充分的学习并利用到所有的功能,感受到实验的乐趣.

7. 程序源码附录

 

SUBDESIGN keyin ( keyin : input; keyout : output; clk : input; ) variable sm:machine of bits(sb1,sb0) with states (s3=b"10",s2=b"11",s1=b"01",s0=b"00"); begin sm.clk=clk; table sm,keyin => sm; s0,0 => s0; s1,0 => s0; s2,0 => s0; s3,0 => s0; s0,1 => s1; s1,1 => s2; s2,1 => s3; s3,1 => s3; end table; keyout=sb1&!sb0; end;  

 

SUBDESIGN getkey3 ( in1,in2,in3,in4,in5,in6,in7,in8,in9: input; sel : output; keyout[3..0] : output; ) begin defaults keyout[]=h"0"; sel=b"0"; end defaults; table in1,in2,in3,in4,in5,in6,in7,in8,in9 => keyout[3..0],sel; h"1",h"0",h"0",h"0",h"0",h"0",h"0",h"0",b"0" => b"0001",b"1"; h"0",h"1",h"0",h"0",h"0",h"0",h"0",h"0",b"0" => b"0010",b"1"; h"0",h"0",h"1",h"0",h"0",h"0",h"0",h"0",b"0" => b"0011",b"1"; h"0",h"0",h"0",h"1",h"0",h"0",h"0",h"0",b"0" => b"0100",b"1"; h"0",h"0",h"0",h"0",h"1",h"0",h"0",h"0",b"0" => b"0101",b"1"; h"0",h"0",h"0",h"0",h"0",h"1",h"0",h"0",b"0" => b"0110",b"1"; h"0",h"0",h"0",h"0",h"0",h"0",h"1",h"0",b"0" => b"0111",b"1"; h"0",h"0",h"0",h"0",h"0",h"0",h"0",h"1",b"0" => b"1000",b"1"; h"0",h"0",h"0",h"0",h"0",h"0",h"0",h"0",b"1" => b"1001",b"1"; end table; end;  

 

SUBDESIGN main ( set: input; clk : input; sel : input; outclk[8..1]:output; outclkb[8..1]:output; en : output; ) variable count[3..0] : dff; begin defaults outclk[8..1]=h"0"; outclkb[8..1]=h"0"; end defaults; count[].clk=sel; if clk and sel then if set then outclkb[8..1]=h"0"; table count[] => outclk[8..1]; h"1" => h"1"; h"2" => h"2"; h"3" => h"4"; h"4" => h"8"; h"5" => h"10"; h"6" => h"20"; h"7" => h"40"; h"8" => h"80"; end table; else outclk[8..1]=h"0"; table count[] => outclkb[8..1]; h"1" => h"1"; h"2" => h"2"; h"3" => h"4"; h"4" => h"8"; h"5" => h"10"; h"6" => h"20"; h"7" => h"40"; h"8" => h"80"; end table; end if; else outclk[8..1]=h"0"; outclkb[8..1]=h"0"; end if; if count[].q==8 then count[].d=1; else count[].d=count[].q+1; end if; if count[].q==8 then en=b"1"; else en=b"0"; end if; end;  

 

SUBDESIGN save8dig ( clk[8..1] : input; data[3..0] : input; s1[3..0]:output; s2[3..0]:output; s3[3..0]:output; s4[3..0]:output; s5[3..0]:output; s6[3..0]:output; s7[3..0]:output; s8[3..0]:output; ) variable s1[3..0]:dff; s2[3..0]:dff; s3[3..0]:dff; s4[3..0]:dff; s5[3..0]:dff; s6[3..0]:dff; s7[3..0]:dff; s8[3..0]:dff; begin s1[].clk=clk[1]; s2[].clk=clk[2]; s3[].clk=clk[3]; s4[].clk=clk[4]; s5[].clk=clk[5]; s6[].clk=clk[6]; s7[].clk=clk[7]; s8[].clk=clk[8]; s1[].d=data[]; s2[].d=data[]; s3[].d=data[]; s4[].d=data[]; s5[].d=data[]; s6[].d=data[]; s7[].d=data[]; s8[].d=data[]; end;  

 

SUBDESIGN dotdisp ( set : input; en : input; equ : input; clk[2..0] : input; row[8..1] : output; red[16..1] : output; green[16..1] : output; ) begin if en then table set,equ,clk[2..0] => row[8..1],red[16..1],green[16..1]; b"0",b"1",h"0" => h"1",h"ffff",h"dbc3"; b"0",b"1",h"1" => h"2",h"ffff",h"ebdb"; b"0",b"1",h"2" => h"4",h"ffff",h"ebdb"; b"0",b"1",h"3" => h"8",h"ffff",h"f3db"; b"0",b"1",h"4" => h"10",h"ffff",h"f3db"; b"0",b"1",h"5" => h"20",h"ffff",h"ebdb"; b"0",b"1",h"6" => h"40",h"ffff",h"ebdb"; b"0",b"1",h"7" => h"80",h"ffff",h"dbc3"; b"1",b"0",h"0" => h"1",h"ffff",h"dbc3"; b"1",b"0",h"1" => h"2",h"ffff",h"ebdb"; b"1",b"0",h"2" => h"4",h"ffff",h"ebdb"; b"1",b"0",h"3" => h"8",h"ffff",h"f3db"; b"1",b"0",h"4" => h"10",h"ffff",h"f3db"; b"1",b"0",h"5" => h"20",h"ffff",h"ebdb"; b"1",b"0",h"6" => h"40",h"ffff",h"ebdb"; b"1",b"0",h"7" => h"80",h"ffff",h"dbc3"; b"0",b"0",h"0" => h"1",h"c3bf",h"ffff"; b"0",b"0",h"1" => h"2",h"dbbd",h"ffff"; b"0",b"0",h"2" => h"4",h"dbb9",h"ffff"; b"0",b"0",h"3" => h"8",h"dbb5",h"ffff"; b"0",b"0",h"4" => h"10",h"dbad",h"ffff"; b"0",b"0",h"5" => h"20",h"db9d",h"ffff"; b"0",b"0",h"6" => h"40",h"dbbd",h"ffff"; b"0",b"0",h"7" => h"80",h"c3fd",h"ffff"; end table; else row[]=h"ff"; red[]=h"ffff"; green[]=h"ffff"; end if; end;  

 

SUBDESIGN compare ( en : input; in11[3..0] : input; in12[3..0] : input; in13[3..0] : input; in14[3..0] : input; in15[3..0] : input; in16[3..0] : input; in17[3..0] : input; in18[3..0] : input; in21[3..0] : input; in22[3..0] : input; in23[3..0] : input; in24[3..0] : input; in25[3..0] : input; in26[3..0] : input; in27[3..0] : input; in28[3..0] : input; equ : output; ) begin if en and in11[]==in21[] and in12[]==in22[] and in13[]==in23[] and in14[]==in24[] and in15[]==in25[] and in16[]==in26[] and in17[]==in27[] and in18[]==in28[] then equ=b"1"; else equ=b"0"; end if; end;  

 

SUBDESIGN saveselect ( sel:input; in11[3..0] : input; in12[3..0] : input; in13[3..0] : input; in14[3..0] : input; in15[3..0] : input; in16[3..0] : input; in17[3..0] : input; in18[3..0] : input; in21[3..0] : input; in22[3..0] : input; in23[3..0] : input; in24[3..0] : input; in25[3..0] : input; in26[3..0] : input; in27[3..0] : input; in28[3..0] : input; out1[3..0] : output; out2[3..0] : output; out3[3..0] : output; out4[3..0] : output; out5[3..0] : output; out6[3..0] : output; out7[3..0] : output; out8[3..0] : output; ) begin if !sel then out1[]=in21[]; out2[]=in22[]; out3[]=in23[]; out4[]=in24[]; out5[]=in25[]; out6[]=in26[]; out7[]=in27[]; out8[]=in28[]; else out1[]=in11[]; out2[]=in12[]; out3[]=in13[]; out4[]=in14[]; out5[]=in15[]; out6[]=in16[]; out7[]=in17[]; out8[]=in18[]; end if; end; 

 

SUBDESIGN digselect ( clk[2..0]:input; in1[3..0]:input; in2[3..0]:input; in3[3..0]:input; in4[3..0]:input; in5[3..0]:input; in6[3..0]:input; in7[3..0]:input; in8[3..0]:input; digout[3..0]:output; outsel[8..1]:output; ) begin if clk[]==b"000" then outsel[]=h"1"; digout[]=in1[]; elsif clk[]==b"001" then outsel[]=h"2"; digout[]=in2[]; elsif clk[]==b"010" then outsel[]=h"4"; digout[]=in3[]; elsif clk[]==b"011" then outsel[]=h"8"; digout[]=in4[]; elsif clk[]==b"100" then outsel[]=h"10"; digout[]=in5[]; elsif clk[]==b"101" then outsel[]=h"20"; digout[]=in6[]; elsif clk[]==b"110" then outsel[]=h"40"; digout[]=in7[]; else outsel[]=h"80"; digout[]=in8[]; end if; end; 

 

subdesign 7segment ( i[3..0]: input; a,b,c,d,e,f,g: output; ) begin table i[3..0]=>a,b,c,d,e,f,g; h"0" =>0,0,0,0,0,0,1; h"1" =>1,0,0,1,1,1,1; h"2" =>0,0,1,0,0,1,0; h"3" =>0,0,0,0,1,1,0; h"4" =>1,0,0,1,1,0,0; h"5" =>0,1,0,0,1,0,0; h"6" =>0,1,0,0,0,0,0; h"7" =>0,0,0,1,1,1,1; h"8" =>0,0,0,0,0,0,0; h"9" =>0,0,0,0,1,0,0; end table; end;  

 

SUBDESIGN player ( set : input; clk : input; en : input; equ : input; alow,ahigh,al,blow,bhigh,clow,chigh,dlow,dhigh,elow,ehigh,flow,fhigh,glow,ghigh: input; spk : output; ) variable count[3..0] : dff; begin count[].clk=clk; if count[].q==0 and en then count[].d=1; end if; if count[].q==8 and en then count[].d=8; end if; if count[].q==8 and !en then count[].d=0; end if; if count[].q==1 and en then count[].d=count[].q+1; if equ or set then spk=ahigh; else spk=glow; end if; elsif count[].q==2 and en then count[].d=count[].q+1; if equ or set then spk=bhigh; else spk=flow; end if; elsif count[].q==3 and en then count[].d=count[].q+1; if equ or set then spk=chigh; else spk=elow; end if; elsif count[].q==4 and en then count[].d=count[].q+1; if equ or set then spk=dhigh; else spk=dlow; end if; elsif count[].q==5 and en then count[].d=count[].q+1; if equ or set then spk=ehigh; else spk=clow; end if; elsif count[].q==6 and en then count[].d=count[].q+1; if equ or set then spk=fhigh; else spk=blow; end if; elsif count[].q==7 and en then count[].d=count[].q+1; if equ or set then spk=ghigh; else spk=alow; end if; else spk=gnd; end if; end;  

 

SUBDESIGN freqaa ( clk : input; freqaa: output; ) variable count[20..0]:dff; begin defaults freqaa=gnd; end defaults; count[].clk=clk; if count[]==h"8e0" then freqaa=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqbb ( clk : input; freqbb: output; ) variable count[20..0]:dff; begin defaults freqbb=gnd; end defaults; count[].clk=clk; if count[]==h"1096" then freqbb=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqcc ( clk : input; freqcc: output; ) variable count[20..0]:dff; begin defaults freqcc=gnd; end defaults; count[].clk=clk; if count[]==h"fa9" then freqcc=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqdd ( clk : input; freqdd: output; ) variable count[20..0]:dff; begin defaults freqdd=gnd; end defaults; count[].clk=clk; if count[]==h"df1" then freqdd=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqee ( clk : input; freqee: output; ) variable count[20..0]:dff; begin defaults freqee=gnd; end defaults; count[].clk=clk; if count[]==h"bda" then freqee=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqff ( clk : input; freqff: output; ) variable count[20..0]:dff; begin defaults freqff=gnd; end defaults; count[].clk=clk; if count[]==h"b2f" then freqff=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN freqgg ( clk : input; freqgg: output; ) variable count[20..0]:dff; begin defaults freqgg=gnd; end defaults; count[].clk=clk; if count[]==h"9f7" then freqgg=vcc; count[].d=h"0"; else count[].d=count[].q+1; end if; end;  

 

SUBDESIGN frediv ( clk : input; freout : output; ) variable count:dff; begin count.clk=clk; if count.q==0 then count.d=b"1"; else count.d=b"0"; end if; freout=count.q; end;  

 

-EOF-

你可能感兴趣的:(实验报告)