




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2015-2016学年第一学期数字电路实验报告 实验名称: 打地鼠实验 学 院: 信息与通信工程学院 专 业: 电子信息工程 班 级: 班内序号: 学 号: 姓 名: 北京邮电大学 时间:2015年11月8日一、设计课题的任务要求1、 设计一个挑战反应速度的“打地鼠”游戏,采用用88 双色点阵显示游戏界面,其中游戏边界采用绿色LED 显示,随机出现的地鼠采用红色LED 显示,游戏有16 个洞穴,如图1 所示。2、 游戏洞穴每次随机出现一个地鼠,每个地鼠的最长保持时间为2 秒,2 秒后随机出现下一个地鼠。以44 键盘的按键代表锤子,16 个洞穴与16 个按键一一对应,一旦锤子在2 秒内击中地鼠,地鼠消失,数码管计分器分数加1 分;若锤子一直没有击中地鼠,2 秒后该地鼠消失。用两个数码管显示游戏成绩,当游戏成绩达到10 分时游戏结束,点阵显示字符“V”。3、 用两个数码管对整个游戏进行倒计时,当游戏时间超过59 秒而成绩未达到10 分时,游戏失败,点阵显示字符“X”。4、 按复位键重新开始游戏,并开始倒计时。二、系统设计1.设计思路用8*8双色点阵显示游戏界面,其中游戏边界使用6*6,红色LED灯表示地鼠出现,4*4键盘对应锤子,两个数码管显示游戏倒计时,两个数码管显示分数,当游戏成绩达到十分时游戏结束,点阵显示“V”,当游戏时间超过59秒而成绩未达到10分时,游戏失败,点阵实现“X”。记分达到十分开始倒计时记分加一地鼠保持2秒锤子打中地鼠出现倒计时结束开始2. 总体框图是是复位游戏失败游戏成功否否是3. 分块设计分数模块地鼠模块到计时模块键盘模块判断模块分频模块控制模块3、 仿真波形及波形分析 因按照原程序仿真时间过长,所以将原程序所有分频统一调小1000倍,从而实现仿真中60ms等于实际过程中60s的效果,并在过程中人为设置按键,复位和暂停观察仿真结果。3.1 数码管扫描如图为键盘扫描波形。因为6个数码管的管脚连接在一起,无法使其同时显示不同的数字,所以需要对数码管进行扫描,使不同的数码管在不同的时间亮起,显示不同的数字,并通过人眼的视觉暂留效应实现数字的清晰显示。3.2 键盘扫描如图为键盘扫描波形。tempclk3(1000Hz)每发生一次,kbrow的一位变为低电平,其余三位为高电平,表示扫描该行,并记录此时数值。当kbrow的高位到低位依次变为低电平,表示进行了一次完整的扫描。3.3 点阵扫描如图为点阵扫描波形。Tempclk4(500Hz)每发生一次,row的一位变为低电平,其余七位为高电平,表示扫描该行,。当row的高位到低位依次变为低电平,表示进行了一次完整的扫描。3.4 田地边界如图为田地边界的显示(绿色LED灯)。此处稍作说明的是,此程序中的边界与课题要求中稍有不同,占据点阵正中央的6*6边界,完全对称。3.5 地鼠出现如图为地鼠出现模块波形。可以看到,当未按下或正确按下按键时,colr(红色LED灯)波形2s变化一次,即地鼠2s变化出现。当正确按下按键,波形立刻变化,即地鼠立刻变换位置。3.6 暂停如图为按下暂停键之后的波形。可以看到,点阵(colg和colr)不再亮起。程序暂停。3.7 复位如图为按下复位键之后波形。可以看到,colr的波形按照初始时刻波形重新变化,表示游戏重新开始。 4、 源程序 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;-entity dadishu isport(clk: in std_logic;rst: in std_logic; -kbrow: in std_logic_vector(3 downto 0); kbcol:out std_logic_vector(3 downto 0); -键盘-row: out std_logic_vector(7 downto 0);colg: out std_logic_vector(7 downto 0); colr: out std_logic_vector(7 downto 0);-shumaguan:out std_logic_vector(6 downto 0);catout: out std_logic_vector(5 downto 0) ;-数码管-clear: in std_logic; -BTN0- 复位- mode: in std_logic );end entity;architecture a of dadishu is-TYPE matrix_index is array (29 downto 0) of std_logic_vector(15 downto 0);constant dishu : matrix_index:=( x4000,x0800,x0001,x8000,x0020,x0010,x0100,x0010,x8000,x0002, x4000,x0080,x0010,x0002,x0800,x4000,x0001,x0400,x0020,x8000, x0002,x0800,x0001,x1000,x0200,x0008,x4000,x0001,x0008,x0010 );signal cnt: integer range 0 to 10000;signal cnt2: integer range 0 to 50000000;signal clk_tmp : std_logic;signal st1: std_logic_vector(7 downto 0); -点阵-signal data: std_logic_vector(7 downto 0);signal ling: std_logic_vector(1 downto 0);signal change: integer range 0 to 29;signal k: std_logic_vector(15 downto 0):=x0000;signal red: std_logic_vector(7 downto 0);signal location: std_logic_vector(7 downto 0);-signal scanand:std_logic_vector(7 downto 0);signal col: std_logic_vector(3 downto 0); signal cntscan:integer range 0 to 3; signal clk_tmp1:std_logic; signal key: std_logic_vector(15 downto 0):=x1111; -jianpan-signal counter1:integer range 0 to 3;signal counter2:integer range 0 to 50000;signal n: std_logic_vector(15 downto 0);-signal co: std_logic_vector(6 downto 0);signal co1: std_logic_vector(6 downto 0); signal co2: std_logic_vector(6 downto 0); signal co3: std_logic_vector(6 downto 0); -记分signal co4: std_logic_vector(6 downto 0);signal cat: std_logic_vector(5 downto 0);signal up: integer range 0 to 1:=0;signal counter3:integer range 0 to 25000000; -signal i: integer range 0 to 20;signal j: integer range 0 to 60; signal vx: integer range 0 to 2; signal stop: integer range 0 to 1 :=0; - game over-signal fuwei: integer range 0 to 1:=0; -复位beginling=00;- dianzhenprocess(clk,rst)beginif rising_edge(clk) and rst=0thenif cnt=10000 thencnt=0; clk_tmp= not clk_tmp;elsecnt=cnt+1;end if;end if;end process;process(clk_tmp1,up,rst,fuwei)variable count9:integer range 0 to 1000 :=0; beginif falling_edge(clk_tmp1) and fuwei=1 thenchange=29;elsif falling_edge(clk_tmp1) and fuwei=0 thenif up=1 thencount9:=0;if change=0 then change=29;else change=change-1;end if;elsif up=0 thenif count9=1000 thencount9:=0;if change=0 then change=29;else changekkkkkkkkkkkkkkkkkkkkkkkkkkkkkk=dishu(0);end case;end if;end process; process(clk_tmp,rst)beginif rising_edge(clk_tmp) and rst=0 then if (vx=2) thenif st1=00000000 or st1=11111110 thenst1=01111111; data=11111100;red=00000000;elsif st1=01111111 thenst1=10111111; data=1& 0000&1&ling(1 downto 0);red=0&k(15 downto 12)&000;elsif st1=10111111 thenst1=11011111; data=1 &0000&1&ling(1 downto 0);red=0&k(11 downto 8)&000;elsif st1=11011111 thenst1=11101111; data=1&0000&1&ling(1 downto 0);red=0&k(7 downto 4)&000;elsif st1=11101111 thenst1=11110111; data=1&0000&1&ling(1 downto 0);red=0&k(3 downto 0)&000;elsif st1=11110111 thenst1=11111011; data=11111100;red=00000000;elsif st1=11111011 thenst1=11111101; data=00000000;red=00000000;elsif st1=11111101 thenst1=11111110; data=00000000;red=00000000;end if;elsif (vx=1) then if st1=00000000 or st1=11111110 thenst1=01111111; data=00000000;red=00000000;elsif st1=01111111 thenst1=10111111; data=01000001;red=00000000;elsif st1=10111111 thenst1=11011111; data=00100010;red=00000000;elsif st1=11011111 thenst1=11101111; data=00010100;red=00000000;elsif st1=11101111 thenst1=11110111; data=00001000;red=00000000;elsif st1=11110111 thenst1=11111011; data=00000000;red=00000000;elsif st1=11111011 thenst1=11111101; data=00000000;red=00000000;elsif st1=11111101 thenst1=11111110; data=00000000;red=00000000;end if;elsif (vx=0) thenif st1=00000000 or st1=11111110 thenst1=01111111; data=00000000;red=10000001;elsif st1=01111111 thenst1=10111111; data=00000000;red=01000010;elsif st1=10111111 thenst1=11011111; data=00000000;red=00100100;elsif st1=11011111 thenst1=11101111; data=00000000;red=00011000;elsif st1=11101111 thenst1=11110111; data=00000000;red=00011000;elsif st1=11110111 thenst1=11111011; data=00000000;red=00100100;elsif st1=11111011 thenst1=11111101; data=00000000;red=01000010;elsif st1=11111101 thenst1=11111110; data=00000000;red=10000001;end if;end if;end if;end process;row=st1;colg=data;colr=red;-键盘process(clk,rst)beginif rising_edge(clk) and rst=0 thenif counter2=50000 thencounter2=0; clk_tmp1= not clk_tmp1;elsecounter2=counter2+1;end if;end if;end process;process(clk_tmp1,rst)begin if rising_edge(clk_tmp1) and rst=0 then if cntscan=3 then cntscan=0; else cntscancolcolcolcol=1110; end case; end if; end process; process(clk_tmp1,rst) begin if falling_edge(clk_tmp1) and rst=0 then if kbrow=1111 then if counter1=3 then counter1=0; else counter1=counter1+1; end if; key=x1111; else counter1 key key key key key key key key key key key key key key key keyNUll; end case; end if; end if; end process;scanand=col&kbrow;kbcol=col;process(clk_tmp1)begin if falling_edge(clk_tmp1) thenif key = k then up=1; else up=0; -判断 end if;end if;end process;scanand=col&kbrow;kbcolcat=101111; cocat=011111; cocat=111110; cocat=111101; cocat=101111; co=co1;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;beginif falling_edge(clk_tmp1) and fuwei=1 thenscore1:=0;score2:=0;i=0;elsif falling_edge(clk_tmp1) and stop=1 and fuwei=0 thenscore1:=score1;score2 :=score2;i=i;elsif falling_edge(clk_tmp1) and stop=0 and fuwei=0 thenif(up=1)thenscore1 := score1+1;i=i+1;if(score1=10)thenscore1:=0;score2:= score2+1;end if;else score1:=score1;score2 :=score2;i co3 co3 co3 co3 co3 co3 co3 co3 co3 co3 co3 co4 co4 co4 co4=1111110; -0end 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;beginif (clk_tmp1event and clk_tmp1=1) and fuwei=1 thencount1:=0; count2:=6;j=0;elsif(clk_tmp1event and clk_tmp1=1) and fuwei=0 thenif stop=1 then count1:=count1; count2:=count2;j=j;elsif stop=0 thenif count3=500 then count3:=0; count1:=count1-1; j co1 co1 co1 co1 co1 co1 co1 co1 co1 co1 co1 co2 co2 co2 co2 co2 co2 co2 co2=1111110; -0end case;end if;end process ;catout=cat;shumaguan=co;-game overprocess(clk_tmp1,mode)beginif rising_edge(clk_tmp1) and mode=0 thenif clear=1 then fuwei=1; stop=0;elsif clear=0 thenif i=10 and j60 thenvx=1; fuwei=0; stop=1; -显示velsif i10 and j=60 thenvx=0; fuwei=0; stop=1; -显示xelse vx=2; stop=stop; fuwei=0;end if;end if; end if; end process;-复位end a;5、 功能说明及资源利用情况功能说明: 游戏开始,数码管后两位显示60秒倒计时,并且点阵上在4*4区域内随机出现一个点,此时,在键盘部分按键,如果按键
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 纪检培训试题及答案
- 河南学校面试题及答案
- 雨中跳舞测试题及答案
- 德语模拟测试题及答案
- 2025年广东省安全员(A证)第四批(主要负责人)证考试练习题库(含答案)
- 2025年中小学生卫生知识大赛试题(附含答案)
- 2024年广西公务员考试真题及答案
- 北京育儿知识培训班课件
- 2025年继续教育公需课必修课考试题库附含参考答案
- (健康档案老年人慢性病)模拟试卷含答案
- 2023施工技术交底编制与管理标准培训
- 物业管理考核细则-
- GB/T 3683-2023橡胶软管及软管组合件油基或水基流体适用的钢丝编织增强液压型规范
- 义教课程标准(2022年版)解读·徐蓝
- GA/T 954-2011法庭科学工具痕迹中凹陷痕迹的检验规范
- DB1331T004-2022雄安新区数据安全建设导则
- 环水保工程监理细则
- DB11-T1834-2021 城市道路工程施工技术规程高清最新版
- 手工电弧焊焊接头基本形式与尺寸
- 开拓进取:零碳汽车的材料脱碳之路
- (完整版)自我护理能力量表ESCA
评论
0/150
提交评论