北邮数电综合实验迷宫._第1页
北邮数电综合实验迷宫._第2页
北邮数电综合实验迷宫._第3页
北邮数电综合实验迷宫._第4页
北邮数电综合实验迷宫._第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

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

文档简介

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

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

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

4、示catrow red,greensech,secl count坐标及显示控制器30s倒计时控制out_state clk_out1(点阵扫描) startclk_out3(1Hz) 时钟 防抖 分频器 reset k_l,r,u,d clk_out2(控制) clk_out4(200Hz) clk_in方向按键复位按键(4)ASM图reset=1stuck=0 andm_l/r/u/d=1 成功移动start=1/reset=1win=1开始reset=1stuck=0 and m_l/r/u/d=1 stuck=1 stuck=1 or time_up=1m_l/r/u/d=0失败不动re

5、set=1 time_up=1 stuck=1/m_l/r/u/d=0reset=1(5)控制器逻辑流程图显示开始界面GO 是否开始?N 是否复位?YY 选关1?显示迷宫1YN显示迷宫2N 左移? 左移YN 右移? 右移Y N 上移? 上移YN 下移? 下移YN N 成功? 时间到? 碰壁?NN 成功 失败YY§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;cl

6、k_out3:out std_logic;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:i

7、n std_logic;out_state: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 -cont

8、rol 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_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

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

10、e 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,停止计时。由sec_outl,sec_

11、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 prevention port(clk : in std_logic;btn_in : in std_logic;btn_out : out std_logic);end

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

14、:in std_logic;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

15、_green:out std_logic_vector(7 downto 0);end;architecture struct of moon_maze is 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;clk_out4:out std_logic);end component;component shake_prv is -shake preven

16、tion port(clk : 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;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

17、: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;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_l

18、ogic_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 component;component led_control -control the countdownport(res:in std_logic;start:in std_logic;win:in std_logic;clk_in:in s

19、td_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;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:ou

20、t std_logic_vector(3 downto 0); end component;component led -segment decoderport(count:in std_logic_vector(3 downto 0);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_l

21、ogic;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:fe

22、npin port map(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)

23、;u5:control port map(round=>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 port map(clk_2=>clk_temp1,s_reset=>reset,s_start=>start,round=&

24、gt;round,time_up=>temp_lose,win=>temp_win,x_g=>x_temp,y_g=>y_temp,row=>out_row,red=>out_red,green=>out_green);u7:led_control port map(res=>reset,start=>start,win=>temp_win,clk_in=>clk_temp3,state_out=>temp_lose,sec_outl=>data_templ,sec_outh=>data_temph);u8:l

25、ed_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_seg);end;分频器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin isport(clk_in:in std_logic;clk_o

26、ut1: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 range 0 to 2499;signal cnt2:integer range 0 to 499;signal cnt3:integer range 0 to 4

27、9;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_in'event and clk_in='1' thenif cnt1=2499 thenclk_temp1<=not clk_temp1;cnt1<=0; elsecnt1<=cnt1

28、+1;end if;end if;end process p1;clk_out1<=clk_temp1;p2:process(clk_temp1)-10Hzbeginif clk_temp1'event and clk_temp1='1'thenif cnt2=499 thenclk_temp2<=not clk_temp2;cnt2<=0;elsecnt2<=cnt2+1;end if;end if;end process p2;clk_out2<=clk_temp2;p3:process(clk_temp2)-1Hzbeginif cl

29、k_temp2'event and clk_temp2='1'thenif 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_temp1'event and clk_temp1='1'thenif cnt4=24 thenclk_temp4<=not clk_temp4;c

30、nt4<=0;elsecnt4<=cnt4+1;end if;end if;end process p4;clk_out4<=clk_temp4;end behave;迷宫控制器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity control isport(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:i

31、n std_logic;out_state:out std_logic;-out_stuck:out std_logic;out_y_g:out std_logic_vector(3 downto 0);out_x_g:out std_logic_vector(3 downto 0);end;architecture behave of control issignal win_temp:std_logic;-signal stuck_temp:std_logic;signal k_l,k_r,k_u,k_d:std_logic;signal x_t:std_logic_vector(3 do

32、wnto 0);signal y_t:std_logic_vector(3 downto 0);signal x:integer range 0 to 7;signal y:integer range 0 to 7;beginp1:process(x,y)-x,y send to translatorbegincase x iswhen 0 =>x_t<="0000"when 1 =>x_t<="0001"when 2 =>x_t<="0010"when 3 =>x_t<="0

33、011"when 4 =>x_t<="0100"when 5 =>x_t<="0101"when 6 =>x_t<="0110"when 7 =>x_t<="0111"end case;case y iswhen 0 =>y_t<="0000"when 1 =>y_t<="0001"when 2 =>y_t<="0010"when 3 =>y_t<=&

34、quot;0011"when 4 =>y_t<="0100"when 5 =>y_t<="0101"when 6 =>y_t<="0110"when 7 =>y_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;k_u<=m_u

35、p;k_d<=m_down;end process p2;p3:process(round,clk_1,p_rst,p_start,k_l,k_r,k_u,k_d)beginif(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&

36、#39;)and(clk_1'event 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 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=

37、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 if;end if;if(k

38、_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)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'

39、;elsif(round='1') and (p_start='0')thenx<=7;y<=1;-stuck_temp<='0'elseif (round='1') and (clk_1'event 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(

40、x=1)or(x=2)or(x=3)or(x=4)or(x=5)thenx<=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='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)

41、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)theny<=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(

42、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(x=0 and y=6)thenwin_temp<='1'else win_temp

43、<='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;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity show_control isport(clk_2:in std_logic;s_start:in std_log

44、ic;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_logic_vector(7 downto 0);end;architecture struct of show_co

45、ntrol issignal temp_clk:std_logic;signal count:integer 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_2'event and clk_2='1&#

46、39;)thenif count=2 thencount<=0;temp_clk<=not temp_clk;elsecount<=count+1;end if;end if;end process p1;p2:process(temp_clk,s_start) -sweep countbeginif(temp_clk'event and temp_clk='1')thenif count_sweep=8 thencount_sweep<=0;elsecount_sweep<=count_sweep+1;end if;end if;end

47、process p2;p3:process(clk_2,count_sweep,s_reset,s_start,win,x_g,y_g,round)beginif s_reset='1' thenout_row<="11111111"elseif(clk_2'event and clk_2='1')thenif(s_start='0')then -startcase count_sweep is-GOwhen 0=>out_row<="01111111"out_r<=&quo

48、t;00000000"out_g<="00000000"when 1=>out_row<="10111111"out_r<="11101110"out_g<="11101110"when 2=>out_row<="11011111"out_r<="10100001"out_g<="10100001"when 3=>out_row<="11101111"out_r

49、<="10100001"out_g<="10100001"when 4=>out_row<="11110111"out_r<="10101101"out_g<="10101101"when 5=>out_row<="11111011"out_r<="10101001"out_g<="10101001"when 6=>out_row<="11111101&q

50、uot;out_r<="11101110"out_g<="11101110"when 7=>out_row<="11111110"out_r<="00000000"out_g<="00000000"when others=>out_row<="11111111"out_r<="00000000"out_g<="00000000"end case;elseif(time_up=&

51、#39;1')then -losecase count_sweep is -broken heartwhen 7=>out_row<="01111111"out_r<="01000010"out_g<="00000000"when 6=>out_row<="10111111"out_r<="11100111"out_g<="00000000"when 5=>out_row<="11011111&qu

52、ot;out_r<="11100111"out_g<="00000000"when 4=>out_row<="11101111"out_r<="11100111"out_g<="00000000"when 3=>out_row<="11110111"out_r<="01100110"out_g<="00000000"when 2=>out_row<="11

53、111011"out_r<="00100100"out_g<="00000000"when 1=>out_row<="11111101"out_r<="00000000"out_g<="00000000"when 0=>out_row<="11111110"out_r<="00000000"out_g<="00000000"when others=>out_ro

54、w<="11111111"out_r<="00000000"out_g<="00000000"end case;elseif(win='1')then -successcase count_sweep is -heartwhen 7=>out_row<="01111111"out_r<="00100010"out_g<="00000000"when 6=>out_row<="10111111&qu

55、ot;out_r<="01110111"out_g<="00000000"when 5=>out_row<="11011111"out_r<="01111111"out_g<="00000000"when 4=>out_row<="11101111"out_r<="01111111"out_g<="00000000"when 3=>out_row<="11

56、110111"out_r<="00111110"out_g<="00000000"when 2=>out_row<="11111011"out_r<="00011100"out_g<="00000000"when 1=>out_row<="11111101"out_r<="00001000"out_g<="00000000"when 0=>out_row<="11111110"out_r<="00000000"out_g<="00000000"when others=>out_row<="11111111"out_r<="00000000"out_g<="00000000"end case;elseif(round='0') thencas

温馨提示

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

评论

0/150

提交评论