北邮数电综合实验迷宫模板

上传人:i**** 文档编号:58489159 上传时间:2022-02-28 格式:DOC 页数:30 大小:735.50KB
收藏 版权申诉 举报 下载
北邮数电综合实验迷宫模板_第1页
第1页 / 共30页
北邮数电综合实验迷宫模板_第2页
第2页 / 共30页
北邮数电综合实验迷宫模板_第3页
第3页 / 共30页
资源描述:

《北邮数电综合实验迷宫模板》由会员分享,可在线阅读,更多相关《北邮数电综合实验迷宫模板(30页珍藏版)》请在装配图网上搜索。

1、简易迷宫设计北京邮电大学理学院2014 级数字电路与数字逻辑设计实验报告简易迷宫游戏班级: 2014214104学号: 2014212788班内序号: 17姓名:林玉立2016/6/101简易迷宫设计目录设计课题2系统设计4设计思路错误!未定义书签。4总体框图4分块介绍7仿真波形9源程序11功能说明29资源利用情况29故障及问题分析30总结和结论302简易迷宫设计设计课题简易迷宫设计设计并实现一个简易迷宫游戏机。基本要求:1、用8 8 点阵进行游戏显示。2、迷宫游戏如图1 所示,采用双色点阵显示,其中红色LED 为迷宫墙壁,绿色LED表示人物。通过 BTN0 BTN3 四个按键控制迷宫中的人物

2、进行上下左右移动,使人物从起始点出发,走到迷宫的出口,游戏结束。3、普通计时模式:通过按键BTN7 启动游戏,必须在30 秒内找到出口,否则游戏失败,用两个数码管进行倒计时显示。游戏胜利或者失败均要在88 点阵上有相应的画面出现。4、迷宫中的人物在行走过程中,如果碰到墙壁,保持原地不动。提高要求:1、多种迷宫地图可以选择。2、在计时的基础上增加计步的功能,每按一次控制按键步数加1,碰壁不计算步数,计步结果用数码管显示。3、为游戏增加提示音乐,在不同时间段采用不同频率的信号控制蜂鸣器发声报警。4、增加其他游戏模式。5、自拟其它功能。3简易迷宫设计系统设计1. 设计思路程序采用分模块设计的思路,将

3、具体任务分解成为不同的功能模块,利用component编写,再通过主程序通过port map 语句调用连接。主程序中包括各个子元件的定义及连接语句,子程序分别为分频器模块、防抖模块、点阵显示模块、迷宫人物坐标控制模块、倒计时控制模块、数码管选择模块和数码管显示模块。2. 总体框图(1)顶层框图点阵显示数码管显示迷宫控制器方向按键复位按键启动开关(2)对外接口clk_inout_catstartresetroundmove_l move_rmove_u move_d迷宫控制器out_segout_rowout_redout_green4简易迷宫设计(3)逻辑划分框图数码管选择seg7数点阵cat

4、码数码管显示管rowred,greensech,seclcountout_state坐标及显示控制30s 倒计时控制器clk_out1( 点阵扫描 )startclk_out3(1Hz)resetk_l,r,u,dclk_out2( 控制 )防抖分频器时钟clk_out4(200Hz)clk_in方复向位按按键键(4)ASM 图reset=1stuck=0 andm_l/r/u/d=1start=1/reset=1移动win=1成功reset=1stuck=0 andm_l/r/u/d=1stuck=1开始stuck=1 ortime_up=1m_l/r/u/d=0reset=1不动time_

5、up=1失败stuck=1/m_l/r/u/d=0reset=1(5)控制器逻辑流程图5是否开始?Y选关 1?N显示迷宫2N左移?N简易迷宫设计显示开始界面GONY是否复位?Y显示迷宫1Y左移Y右移?N上移?NY右移上移下移?N碰壁?Y下移NNN时间到?成功?YY失败成功6简易迷宫设计3. 分块介绍(1)分频器component fenpin-divide the frequency to the wantedport(clk_in:in std_logic;clk_out1:out std_logic;clk_out2:out std_logic;clk_out3:out std_logic

6、;clk_out4:out std_logic);end component;输入时钟为50MHz ,通过分频输出10KHz(用于点阵扫描) ,10Hz(用于点阵控制) ,1Hz(用来计数),200Hz(用于防抖设计) 。(2)迷宫控制器component control-logically control the labyrinthineport(round:in std_logic;clk_1:in std_logic;p_rst:in std_logic;p_start:in std_logic;m_left,m_right,m_up,m_down:in std_logic;out_st

7、ate:out std_logic;out_y_g:out std_logic_vector(3 downto 0);out_x_g:out std_logic_vector(3 downto 0);end component;通过按键输入的高低电平来控制迷宫点阵。当选关拨码开关为低电平时, 执行迷宫地图, 复位按键重置初始坐标, 当各个方向按键为高电平时, 判断那些坐标的下一位置是墙壁, 通过 if 语句是坐标点位于当前位置不移动, 反之则向规定方向移动一步。当坐标位于出口时,胜利输出状态为1。(3)点阵显示控制器component show_control-control the swee

8、p of rectangleport(clk_2:in std_logic;s_start:in std_logic;round:in std_logic;s_reset:in std_logic;time_up:in std_logic;win:in std_logic;x_g:in std_logic_vector(3 downto 0);y_g:in std_logic_vector(3 downto 0);row:out std_logic_vector(7 downto 0);red:out std_logic_vector(7 downto 0);green:out std_log

9、ic_vector(7 downto 0);end component;7简易迷宫设计当开始拨码开关为低电平时, 点阵显示游戏初始界面 GO;为高电平时, 根据选关开关状态,显示迷宫 1 或 2。当 time_up=1 时,游戏失败,显示破碎的心;当time_up=0 时,游戏正常进行。 (由计时器提供)当状态 win=1 时,显示完整的心;当win=0 时,游戏正常进行。 (由迷宫控制器提供)为保证点阵亮度一致,选择行扫描,通过向量row 中某路选通(即电平为1),显示该行点阵,并由高频时钟信号扫描,产生视觉停留效果,得到点阵显示。(4)计时器component led_control -c

10、ontrol the countdownport(res:in std_logic;start:in std_logic;win:in std_logic;clk_in:in std_logic;state_out:out std_logic;sec_outl:out std_logic_vector(3 downto 0);sec_outh:out std_logic_vector(3 downto 0);end component;由一个从 0 到 30 的变量计数,初始值为 30,每当遇到 1Hz 的时钟上升沿时,计数器减一,直到计数器减为 0,使失败状态为 1,或到输入胜利状态为 1,

11、停止计时。由 sec_outl , sec_outh 将时间的高低位分开,以便与分别控制两个数码管,显示倒计时。(5)数码管选择器component led_select-select data in digital blinkingport(sech,secl:in std_logic_vector(3 downto 0);clk_select:in std_logic;q:out std_logic_vector(5 downto 0);dataout:out std_logic_vector(3 downto 0);end component;30s 计时的高低位分别对应不同的cat 管

12、脚,使相邻的两个数码管显示对应数字,并将计数值提供给数码管显示器。(6)数码管控制器component led-segment decoderport(count:in std_logic_vector(3 downto 0);seg7:out std_logic_vector(6 downto 0);end component;不同的计数值对应不同数码管管脚的高低电平,是数码管显示正确的数字。(7)防抖component shake_prv is -shake preventionport(clk : in std_logic;btn_in : in std_logic;8简易迷宫设计btn

13、_out : out std_logic);end component;通过低频时钟信号(200Hz)将判断按键按下的时间延长以达到防抖的效果。仿真波形开始界面( GO) start=1 ,依次行扫描row ,点阵红色显示GO。失败界面(破碎的心)time_up=1 ,依次行扫描row ,点阵红色显示broken heart 。9简易迷宫设计成功界面(完整的心)win=1 ,依次行扫描row ,点阵红色显示heart 。行走受阻:下行遇障,stuck 为高电平。10简易迷宫设计源程序主程序:library ieee;entity moon_maze isport(clk_in:in std_l

14、ogic;start:in std_logic;reset:in std_logic;round:in std_logic;-stuck:out std_logic;move_l,move_r,move_u,move_d:in std_logic;out_cat:out std_logic_vector(5 downto 0);out_seg:out std_logic_vector(6 downto 0);out_row:out std_logic_vector(7 downto 0);out_red:out std_logic_vector(7 downto 0);out_green:ou

15、t std_logic_vector(7 downto 0);end;architecture struct of moon_maze iscomponent fenpin-divide the frequency to the wantedport(clk_in:in std_logic;clk_out1:out std_logic;clk_out2:out std_logic;clk_out3:out std_logic;clk_out4:out std_logic);end component;component shake_prv is -shake preventionport(cl

16、k : in std_logic;btn_in : in std_logic;btn_out : out std_logic);end component;component control-logically control the labyrinthineport(round:in std_logic;clk_1:in std_logic;11简易迷宫设计p_rst:in std_logic;p_start:in std_logic;m_left,m_right,m_up,m_down:in std_logic;out_state:out std_logic;-out_stuck:out

17、std_logic;out_y_g:out std_logic_vector(3 downto 0);out_x_g:out std_logic_vector(3 downto 0);end component;component show_control-control the sweep of rectangleport(clk_2:in std_logic;s_start:in std_logic;round:in std_logic;s_reset:in std_logic;time_up:in std_logic;win:in std_logic;x_g:in std_logic_v

18、ector(3 downto 0);y_g:in std_logic_vector(3 downto 0);row:out std_logic_vector(7 downto 0);red:out std_logic_vector(7 downto 0);green:out std_logic_vector(7 downto 0);end component;component led_control -control the countdownport(res:in std_logic;start:in std_logic;win:in std_logic;clk_in:in std_log

19、ic;state_out:out std_logic;sec_outl:out std_logic_vector(3 downto 0);sec_outh:out std_logic_vector(3 downto 0);end component;component led_select-select data in digital blinkingport(sech,secl:in std_logic_vector(3 downto 0);clk_select:in std_logic;q:out std_logic_vector(5 downto 0);dataout:out std_l

20、ogic_vector(3 downto 0);end component;component led-segment decoderport(count:in std_logic_vector(3 downto 0);12简易迷宫设计seg7:out std_logic_vector(6 downto 0);end component;signal temp_win:std_logic;signal temp_lose:std_logic;signal clk_temp1:std_logic;signal clk_temp2:std_logic;signal clk_temp3:std_lo

21、gic;signal clk_temp4:std_logic;signal data_templ:std_logic_vector(3 downto 0);signal data_temph:std_logic_vector(3 downto 0);signal data_out:std_logic_vector(3 downto 0);signal x_temp:std_logic_vector(3 downto 0);signal y_temp:std_logic_vector(3 downto 0);signal k_l,k_r,k_u,k_d:std_logic;beginu0:fen

22、pin portmap(clk_in=clk_in,clk_out1=clk_temp1,clk_out2=clk_temp2,clk_out3=clk_temp3,clk_out4=clk_temp4);u1:shake_prv port map(clk_temp4,move_l,k_l);u2:shake_prv port map(clk_temp4,move_r,k_r);u3:shake_prv port map(clk_temp4,move_u,k_u);u4:shake_prv port map(clk_temp4,move_d,k_d);u5:control port map(r

23、ound=round,clk_1=clk_temp2,p_rst=reset,p_start=start,m_left=k_l,m_right=k_r,m_up=k_u,m_down=k_d,out_state=temp_win,out_x_g=x_temp,out_y_g=y_temp);u6:show_control portmap(clk_2=clk_temp1,s_reset=reset,s_start=start,round=round,time_up=temp_lose,win=temp_win,x_g=x_temp,y_g=y_temp,row=out_row,red=out_r

24、ed,green=out_green);u7:led_control portmap(res=reset,start=start,win=temp_win,clk_in=clk_temp3,state_out=temp_lose,sec_outl=data_templ,sec_outh=data_temph);u8:led_select port map(clk_select=clk_temp1,secl=data_templ,sech=data_temph, q=out_cat,dataout=data_out);u9:led port map(count=data_out,seg7=out

25、_seg);end;分频器:library ieee;13简易迷宫设计entity fenpin isport(clk_in:in std_logic;clk_out1:out std_logic;-rectangle and digital sweepclk_out2:out std_logic;-button sweepclk_out3:out std_logic;-second counterclk_out4:out std_logic);-shake_preventionend;architecture behave of fenpin issignal cnt1:integer ra

26、nge 0 to 2499;signal cnt2:integer range 0 to 499;signal cnt3:integer range 0 to 49;signal cnt4:integer range 0 to 25;signal clk_temp1:std_logic;signal clk_temp2:std_logic;signal clk_temp3:std_logic;signal clk_temp4:std_logic;beginp1:process(clk_in)-10KHzbeginif clk_inevent and clk_in=1 thenif cnt1=2

27、499 thenclk_temp1=not clk_temp1;cnt1=0;elsecnt1=cnt1+1;end if;end if;end process p1;clk_out1=clk_temp1;p2:process(clk_temp1)-10Hzbeginif clk_temp1event and clk_temp1=1thenif cnt2=499 thenclk_temp2=not clk_temp2;cnt2=0;elsecnt2=cnt2+1;14简易迷宫设计end if;end if;end process p2;clk_out2=clk_temp2;p3:process

28、(clk_temp2)-1Hzbeginif clk_temp2event and clk_temp2=1thenif cnt3=6 thenclk_temp3=not clk_temp3;cnt3=0;elsecnt3=cnt3+1;end if;end if;end process p3;clk_out3=clk_temp3;p4:process(clk_temp1)-200Hzbeginif clk_temp1event and clk_temp1=1thenif cnt4=24 thenclk_temp4=not clk_temp4;cnt4=0;elsecnt4=cnt4+1;end

29、 if;end if;end process p4;clk_out4x_tx_tx_tx_tx_tx_tx_tx_ty_ty_ty_ty_ty_ty_ty_ty_t=0111;end case;end process p1;out_x_g=x_t;out_y_g=y_t;p2:process(m_left,m_right,m_up,m_down)begink_l=m_left;k_r=m_right;16简易迷宫设计k_u=m_up;k_d=m_down;end process p2;p3:process(round,clk_1,p_rst,p_start,k_l,k_r,k_u,k_d)be

30、ginif(round=0) and (p_rst=1)thenx=7;y=6;-stuck_temp=0;elsif(round=0) and (p_start=0)thenx=7;y=6;-stuck_temp=0;elseif (round=0)and(clk_1event and clk_1=1)thenif(k_l=1)thenif(y=6)and(x=7)or(x=2)or(x=1)or(y=5)and(x=4)or(x=3)or(y=1)and(x=6)or(x=5)or(x=4)or(x=3)thenx=x-1;elsex=x;-stuck_temp=1;end if;end

31、if;if(k_r=1)thenif(y=6)and(x=6)or(x=1)or(y=5)and(x=3)or(x=2)or(y=1)and(x=2)or(x=5)or(x=4)or(x=3)thenx=x+1;elsex=x;-stuck_temp=1;end if;end if;if(k_u=1)thenif(x=2)and(y=1)or(y=2)or(y=3)or(y=4)or(y=5)or(x=4)and(y=3)or(y=4)or(x=6)and(y=1)or(y=2)or(y=3)or(y=4)or(y=5)theny=y+1;elsey=y;-stuck_temp=1;end i

32、f;end if;if(k_d=1)thenif(x=2)and(y=6)or(y=2)or(y=3)or(y=4)or(y=5)or(x=4)and(y=5)or(y=4)17简易迷宫设计or(x=6)and(y=6)or(y=2)or(y=3)or(y=4)or(y=5)theny=y-1;elsey=y;-stuck_temp=1;end if;end if;end if;end if;if (round=1) and (p_rst=1)thenx=7;y=1;-stuck_temp=0;elsif(round=1) and (p_start=0)thenx=7;y=1;-stuck_t

33、emp=0;elseif (round=1) and (clk_1event and clk_1=1)thenif(k_l=1)thenif(y=6)and(x=6)or(x=5)or(x=4)or(y=4)and(x=3)or(x=2)or(x=1)or(y=3)and(x=6)or(y=1)and(x=7)or(x=0)or(x=6)or(x=1)or(x=2)or(x=3)or(x=4)or(x=5)then x=x-1;-(x=6)or(x=1)or(x=2)or(x=3)or(x=4)or(x=5)elsex=x;-stuck_temp=1;end if;end if;if(k_r=

34、1)thenif(y=6)and(x=3)or(x=5)or(x=4)or(y=4)and(x=0)or(x=2)or(x=1)or(y=3)and(x=5)or(y=1)and(x=1)or(x=0)or(x=6)or(x=7)or(x=2)or(x=3)or(x=4)or(x=5)thenx=x+1;elsex=x;-stuck_temp=1;end if;end if;if(k_u=1)thenif(x=1)and(y=4)or(y=5)or(x=3)and(y=5)or(y=4)or(x=5)and(y=1)or(y=2)or(x=6)and(y=3)or(y=4)or(y=5)the

35、n18简易迷宫设计y=y+1;elsey=y;-stuck_temp=1;end if;end if;if(k_d=1)thenif(x=1)and(y=6)or(y=5)or(x=3)and(y=5)or(y=6)or(x=5)and(y=3)or(y=2)or(x=6)and(y=6)or(y=4)or(y=5)theny=y-1;elsey=y;-stuck_temp=1;end if;end if;end if;end if;end process p3;-out_stuck=stuck_temp;p4:process(x,y,round)beginif(round=0) thenif

36、(x=0 and y=6)thenwin_temp=1;else win_temp=0;end if;elseif(x=0 and y=4)thenwin_temp=1;else win_temp=0;end if;end if;end process p4;out_state=win_temp;end;点阵显示控制器:library ieee;19简易迷宫设计entity show_control isport(clk_2:in std_logic;s_start:in std_logic;round:in std_logic;s_reset:in std_logic;time_up:in

37、std_logic;win:in std_logic;x_g:in std_logic_vector(3 downto 0);y_g:in std_logic_vector(3 downto 0);row:out std_logic_vector(7 downto 0);red:out std_logic_vector(7 downto 0);green:out std_logic_vector(7 downto 0);end;architecture struct of show_control issignal temp_clk:std_logic;signal count:integer

38、 range 0 to 2;signal count_sweep:integer range 0 to 8;signal out_row:std_logic_vector(7 downto 0);signal out_r:std_logic_vector(7 downto 0);signal out_g:std_logic_vector(7 downto 0);beginp1:process(clk_2)beginif(clk_2event and clk_2=1)thenif count=2 thencount=0;temp_clk=not temp_clk;elsecount=count+

39、1;end if;end if;end process p1;p2:process(temp_clk,s_start)-sweep countbeginif(temp_clkevent and temp_clk=1)thenif count_sweep=8 thencount_sweep=0;elsecount_sweep=count_sweep+1;20简易迷宫设计end if;end if;end process p2;p3:process(clk_2,count_sweep,s_reset,s_start,win,x_g,y_g,round)beginif s_reset=1 theno

40、ut_rowout_row=01111111;out_r=00000000;out_gout_row=10111111;out_r=11101110;out_gout_row=11011111;out_r=10100001;out_gout_row=11101111;out_r=10100001;out_gout_row=11110111;out_r=10101101;out_gout_row=11111011;out_r=10101001;out_gout_row=11111101;out_r=11101110;out_gout_row=11111110;out_r=00000000;out

41、_gout_row=11111111;out_r=00000000;out_gout_row=01111111;out_r=01000010;out_gout_row=10111111;out_r=11100111;out_gout_row=11011111;out_r=11100111;out_gout_row=11101111;out_r=11100111;out_gout_row=11110111;out_r=01100110;out_gout_row=11111011;out_r=00100100;out_gout_row=11111101;out_r=00000000;out_gou

42、t_row=11111110;out_r=00000000;out_gout_row=11111111;out_r=00000000;out_gout_row=01111111;out_r=00100010;out_gout_row=10111111;out_r=01110111;out_gout_row=11011111;out_r=01111111;out_gout_row=11101111;out_r=01111111;out_gout_row=11110111;out_r=00111110;out_gout_row=11111011;out_r=00011100;out_gout_row=11111101;out_r=00001000;out_gout_row=11111110;out_r=00000000;out_gout_row=11111111;out_r=00000000;out_gout_row=01111111;out_r=11111111;out_gout_row=10111111;out_r=00111000;out_gout_row=11011111;out_r=10100011;out_gout_row=11101111;out_r=10101010;out_gout_row=11110111;out_r=10101010;out_g

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!