北京邮电大学数电实验——打地鼠(3)

2018-11-29 16:30

when 1 =>col<=\ when 2 =>col<=\ when 3 =>col<=\ end case; end if;

end process;

process(clk_tmp1,rst) begin

if falling_edge(clk_tmp1) and rst='0' then if kbrow=\ if counter1=3 then counter1<=0; else

counter1<=counter1+1; end if;

key<=x\ else

counter1<=0; case scanand is

when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when others=>NUll; end case; end if; end if;

end process;

scanand<=col&kbrow; kbcol<=col;

process(clk_tmp1)

begin

if falling_edge(clk_tmp1) then if key = k then up<=1;

else up<=0; ----判断 end if; end if; end process;

scanand<=col&kbrow; kbcol<=col;

-------------------------------------------------------------------------------数码管 process(clk_tmp)

variable count0:integer range 0 to 4 :=0; begin

if rising_edge(clk_tmp) then if(count0=4)then count0:=0; else count0:=count0+1; case count0 is when 0=>cat<=\ when 1=>cat<=\ when 2=>cat<=\ when 3=>cat<=\ when others=>cat<=\ end case; end if; end if; end process ;

process(clk_tmp1,fuwei,stop)

variable score1:integer range 0 to 10 :=0; variable score2:integer range 0 to 10 :=0; begin if falling_edge(clk_tmp1) and fuwei=1 then score1:=0;score2:=0;i<=0; elsif falling_edge(clk_tmp1) and stop=1 and fuwei=0 then score1:=score1;score2 :=score2;i<=i; elsif falling_edge(clk_tmp1) and stop=0 and fuwei=0 then if(up=1)then score1 := score1+1;i<=i+1; if(score1=10)then score1:=0; score2:= score2+1;

end if; else score1:=score1;score2 :=score2;i<=i; end if; case score1 is

when 0=> co3<=\ when 1=> co3<=\ when 2=> co3<=\ when 3=> co3<=\ when 4=> co3<=\ when 5=> co3<=\ when 6=> co3<=\ when 7=> co3<=\ when 8=> co3<=\ when 9=> co3<=\ when others=> co3<=\ end case;

case score2 is when 0=> co4<=\ when 1=> co4<=\ when 2=> co4<=\ when others=> co4<=\ end case; end if; end process ;

--------------------------------------------------------------------倒计时

process(clk_tmp1,fuwei)--1s

variable count1:integer range -1 to 9 :=0; variable count2:integer range 0 to 6 :=6; variable count3:integer range 0 to 500 :=0; begin if (clk_tmp1'event and clk_tmp1='1') and fuwei=1 then count1:=0; count2:=6;j<=0; elsif(clk_tmp1'event and clk_tmp1='1') and fuwei=0 then if stop=1 then count1:=count1; count2:=count2;j<=j; elsif stop=0 then if count3=500 then count3:=0; count1:=count1-1; j<=j+1; if(count1=-1) then count2:=count2-1; count1:=9;

end if; else count3:=count3+1; end if; end if;

case count1 is

when 0=> co1<=\ when 1=> co1<=\ when 2=> co1<=\ when 3=> co1<=\ when 4=> co1<=\ when 5=> co1<=\ when 6=> co1<=\ when 7=> co1<=\ when 8=> co1<=\ when 9=> co1<=\ when others=> co1<=\ end case;

case count2 is

when 0=> co2<=\ when 1=> co2<=\ when 2=> co2<=\ when 3=> co2<=\ when 4=> co2<=\ when 5=> co2<=\ when 6=> co2<=\ when others=> co2<=\ end case; end if; end process ;

catout<=cat; shumaguan<=co;

-------------------------------------------------------------------game over process(clk_tmp1,mode) begin if rising_edge(clk_tmp1) and mode='0' then if clear='1' then fuwei<=1; stop<=0; elsif clear='0' then if i=10 and j<60 then vx<=1; fuwei<=0; stop<=1;

----显示v

elsif i<10 and j=60 then

vx<=0; fuwei<=0; stop<=1; ----显示x else vx<=2; stop<=stop; fuwei<=0; end if; end if; end if; end process;

--------------------------------------------------------------------复位 end a;

五、功能说明及资源利用情况

功能说明:

游戏开始,数码管后两位显示60秒倒计时,并且点阵上在4*4区域内随机出现一个点,此时,在键盘部分按键,如果按键的位置和点阵上显示的点的位置相对应,则在数码管的前两位上的计分部分数值加一,并且点阵上出现一个新的随机点,再进行判断按键操作,依次进行游戏。当计分达到10分,则在点阵上显示一个字母x,如果在60秒内计分没有达到10,则在点阵上显示一个字母v。游戏结束。该游戏利用实验板上的50MHz的晶振,分频后利用新的频率对游戏进行一些基本的控制,用到了实验板上的6*6的点阵部分显示地鼠部分,拨码开关作为游戏的重新开始,数码管部分用到了前两位和后两位分别显示计分和计时。键盘作为锤子对是否打到地鼠进行判断。

按键BTN0是复位,按下之后游戏重新开始,倒计时重新从60秒计时。 资源利用情况:

Total logic elements 401 (1270) 32% Total pins 49 (116 ) 42%

六、故障及问题分析

1.在代码编写到地鼠模块时,发现随机数的产生并没有成功,在参考网上资料后决 定使用数组产生随机数,通过4位16进制数实现该过程。

2.最初的实验程序并没有实现成功打中地鼠后立刻变化的功能,而是继续延时到2s变化。最后,通过放弃2s时钟,而是改用500Hz时钟,在判定up=1后立刻变化数组实现该功能,并且在up=0后加了一个1000倍分频实现未打中则延时2s的功能。

3.在编译过程中发现频率的匹配出现错误,分频代码出现问题,在多次修改后解决。

七、总结和结论

实验中,第一次编写更加复杂的VHDL代码,我一度无法下手。后来通过网上查找,图书馆借阅大量资料,克服了很多困难,最终完成实验。人生的道路就是不断接受新事物,不断学习的过程。这次实验中,我不仅收获了许多知识,熟悉代码编写,也锻炼了自己的动手能力和解决问题的能力。

虽然一整天都待在实验室,虽说很累,但是感觉整个人都充满了能力。怀揣着一份新奇,不断尝试,感觉这样的日子很充实,很快乐。从选择课题的开始,到电路图设计连接,代码编写,到最后的测试修改,一路坎坷。但出现的每一个问题都是一次历练,都是对我们能力的一次沉淀。在共同解决问题的过程中加深了同学友谊,培养了团队合作的能力。

总之,这次实验真的收获了很多,虽然遇到的问题很多,但是解决问题的过程真的是受益匪浅。


北京邮电大学数电实验——打地鼠(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:部编人教版八年级语文上册第三单元测试卷(附答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: