北邮数电综合实验迷宫_第1页
已阅读1页,还剩51页未读 继续免费阅读

下载本文档

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

文档简介

1、北邮数电综合实验迷宫 导读:就爱阅读网友为您分享以下“北邮数电综合实验迷宫”资讯,希望对您有所帮助,感谢您对的支持!简易迷宫设计1 北京邮电大学理学院2014级数字电路与数字逻辑设计实验报告简易迷宫游戏 班级:2014214104学号:2014212788班内序号:17姓名:林玉立 2016/6/10 简易迷宫设计2目录设计课题 . 2系统设计 . 4 设计思路 . . 错误!未定义书签。4总体框图 . . 4分块介绍 . . 7仿真波形 . 9源程序 . 11功能说明 . 29资源利用情况. 29故障及问题分析 . . 30总结和结论 . 30 简易迷宫设计3 设计课题简易迷宫设计 设计并实

2、现一个简易迷宫游戏机。基本要求:1、用 88 点阵进行游戏显示。2、迷宫游戏如图 1 所示,采用双色点阵显示,其中红色LED 为迷宫墙壁,绿色LED 表示人物。通过BTN0BTN3 四个按键控制迷宫中的人物进行上下左右移动,使人 物从起始点出发,走到迷宫的出口,游戏结束。3、普通计时模式:通过按键BTN7 启动游戏,必须在30 秒内找到出口,否则游戏失败, 用两个数码管进行倒计时显示。游戏胜利或者失败均要在88 点阵上有相应的画面 出现。4、迷宫中的人物在行走过程中,如果碰到墙壁,保持原地不动。提高要求:1、多种迷宫地图可以选择。2、在计时的基础上增加计步的功能,每按一次控制按键步数加1,碰壁

3、不计算步数, 计步结果用数码管显示。3、为游戏增加提示音乐,在不同时间段采用不同频率的信号控制蜂鸣器发声报警。4、增加其他游戏模式。5、自拟其它功能。 简易迷宫设计4系统设计1. 设计思路程序采用分模块设计的思路,将具体任务分解成为不同的功能模块,利用component 编写,再通过主程序通过port map语句调用连接。主程序中包括各个子元件的定义及连接语句,子程序分别为分频器模块、防抖模块、点阵显示模块、迷宫人物坐标控制模块、倒计时控制模块、数码管选择模块和数码管显示模块。 2. 总体框图(1)顶层框图 (2)对外接口 简易迷宫设计 5 (3)逻辑划分框图 (5)控制器逻辑流程图简易迷宫设

4、计6 简易迷宫设计7 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;clk_out4:out std_logic);end component;输入时钟为50MHz ,通过分频输出10KHz (用于点阵扫描),10Hz (用于点阵控制),1Hz (用来计数),200Hz (用于防抖设计)。 (2)迷宫控制器component

5、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_y_g:out std_logic_vector(3 downto 0);out_x_g:out std_logic_vector(3 downto 0);end component;通过按键输入的高低电平来控制

6、迷宫点阵。当选关拨码开关为低电平时,执行迷宫地图,复位按键重置初始坐标,当各个方向按键为高电平时,判断那些坐标的下一位置是墙壁,通过if 语句是坐标点位于当前位置不移动,反之则向规定方向移动一步。当坐标位于出口时,胜利输出状态为1。 (3)点阵显示控制器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_lo

7、gic;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 component;简易迷宫设计8 当开始拨码开关为低电平时,点阵显示游戏初始界面GO ;为高电平时,根据选关开关状态,显示迷宫1或2。当time_up=1时,游戏失败,显示破碎的心;当time_up=0时,游戏正

8、常进行。(由计时器提供)当状态win=1时,显示完整的心;当win=0时,游戏正常进行。(由迷宫控制器提供)为保证点阵亮度一致,选择行扫描,通过向量row 中某路选通(即电平为1),显示该行点阵,并由高频时钟信号扫描,产生视觉停留效果,得到点阵显示。 (4)计时器component led_control -control 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

9、_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_outh将时间的高低位分开,以便与分别控制两个数码管,显示倒计时。(5)数码管选择器component led_select -select data in digital blinkingport(sech,secl:in std_logic_vector(3 do

10、wnto 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 管脚,使相邻的两个数码管显示对应数字,并将计数值提供给数码管显示器。 (6)数码管控制器component led -segment decoderport(count:in std_logic_vector(3 downto 0);seg7:out std_logic_vector(6 downto 0);en

11、d component;不同的计数值对应不同数码管管脚的高低电平,是数码管显示正确的数字。 (7)防抖component shake_prv is -shake preventionport(clk : in std_logic;btn_in : in std_logic;简易迷宫设计9 btn_out : out std_logic);end component;通过低频时钟信号(200Hz )将判断按键按下的时间延长以达到防抖的效果。仿真波形 开始界面(GO )start=1,依次行扫描row ,点阵红色显示GO 。 失败界面(破碎的心)time_up=1,依次行扫描row ,点阵红色显示

12、broken heart。 简易迷宫设计10 成功界面(完整的心)win=1,依次行扫描row ,点阵红色显示heart 。 行走受阻:下行遇障,stuck 为高电平。 简易迷宫设计11源程序主程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity moon_maze isport(clk_in:in std_logic;start:in std_logic;reset:in std_logic;round:in std_logic;-stuck:out std_logic;move

13、_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:out std_logic_vector(7 downto 0);end; architecture struct of moon_maze iscomponent fenpin

14、 -divide the frequency to the wanted port(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(clk : in std_logic;btn_in : in std_logic;btn_out : out std_logic);end component; comp

15、onent control -logically control the labyrinthine port(round:in std_logic;clk_1:in std_logic;简易迷宫设计12p_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 std_logic;out_y_g:out std_logic_vector(3 downto 0);out_x_g:out std_logic_vector(

16、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_vector(3 downto 0);y_g:in std_logic_vector(3 downto 0);row:out std_logic_vector

17、(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_logic;state_out:out std_logic;sec_outl:out std_logic_vector(3 downto 0);sec_outh

18、: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_logic_vector(3 downto 0);end component; component led -segment decoderport(c

19、ount:in std_logic_vector(3 downto 0);简易迷宫设计13 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_logic;signal clk_temp4:std_logic;signal data_templ:std_logic_vector(3 dow

20、nto 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:fenpin portmap(clk_in=clk_in,clk_out1=clk_temp1,clk_out2=clk_temp2,clk_ou

21、t3=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(round=round,clk_1=clk_temp2,p_rst=reset,p_start=start, m_left=k_l,m_rig

22、ht=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_red,green=out_green);u7:led_control portmap(res=reset,start=start,w

23、in=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_seg);end; 分频器:library ieee;简易迷宫设计14 use ieee.std_logic_1164.all;

24、use ieee.std_logic_unsigned.all; entity fenpin isport(clk_in:in std_logic;clk_out1:out std_logic;-rectangle and digital sweep clk_out2:out std_logic;-button sweepclk_out3:out std_logic;-second counterclk_out4:out std_logic);-shake_prevention end; architecture behave of fenpin issignal cnt1:integer r

25、ange 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

26、=2499 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;简易迷宫设计15 end if;end if;end process p2;clk_out2=clk_temp2; p3:p

27、rocess(clk_temp2)-1Hzbeginif clk_temp2event and clk_temp2=1then if 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=1then if cnt4=24 thenclk_temp4=not clk_temp4; cnt4=0;elsecnt4

28、=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:in std_logic; out_state:o

29、ut std_logic;简易迷宫设计16 -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 downto 0); si

30、gnal 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 translator begincase x iswhen 0 =x_t=“0000”; when 1 =x_t=“0001”; when 2 =x_t=“0010”; when 3 =x_t=“0011”; when 4 =x_t=“0100”; when 5 =x_t=“0101”; when 6 =x_t=“0110”; wh

31、en 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=“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;

32、k_r=m_right;简易迷宫设计17k_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)begin if(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(

33、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=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

34、=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_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)简易迷宫设计18or(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

35、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_temp=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

36、(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)thenx=x+1;elsex=x;-stuck_temp=1;end if;end

37、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)then简易迷宫设计19 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)then y=y-1;elsey=y;-stuck

38、_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=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 i

39、eee.std_logic_1164.all;简易迷宫设计20 use ieee.std_logic_unsigned.all; 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 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_

40、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 range 0 to 2;signal count_sweep:integer range 0 to 8;signal out_row:std_logic_vector(7 downto 0); signal out_r:s

41、td_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)then if 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 count beginif(temp_clkevent and temp_clk

42、=1)then if count_sweep=8 thencount_sweep=0;elsecount_sweep=count_sweep+1;简易迷宫设计21 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 thenout_row=“11111111”;elseif(clk_2event and clk_2=1)thenif(s_start=0)then -startcase count_sweep is-GOwhe

43、n0=out_row=“01111111”;out_r=“00000000”;out_g=“00000000”; when1=out_row=“10111111”;out_r=“11101110”;out_g=“11101110”; when2=out_row=“11011111”;out_r=“10100001”;out_g=“10100001”; when3=out_row=“11101111”;out_r=“10100001”;out_g=“10100001”; when4=out_row=“11110111”;out_r=“10101101”;out_g=“10101101”; whe

44、n5=out_row=“11111011”;out_r=“10101001”;out_g=“10101001”; when6=out_row=“11111101”;out_r=“11101110”;out_g=“11101110”; when7=out_row=“11111110”;out_r=“00000000”;out_g=“00000000”; whenothers=out_row=“11111111”;out_r=“00000000”;out_g=“00000000”; end case;elseif(time_up=1)then -losecase count_sweep is -b

45、roken heartwhen7=out_row=“01111111”;out_r=“01000010”;out_g=“00000000”; when6=out_row=“10111111”;out_r=“11100111”;out_g=“00000000”; when5=out_row=“11011111”;out_r=“11100111”;out_g=“00000000”; when4=out_row=“11101111”;out_r=“11100111”;out_g=“00000000”; when3=out_row=“11110111”;out_r=“01100110”;out_g=“

46、00000000”;简易迷宫设计22 when2=out_row=“11111011”;out_r=“00100100”;out_g=“00000000”; when1=out_row=“11111101”;out_r=“00000000”;out_g=“00000000”; when0=out_row=“11111110”;out_r=“00000000”;out_g=“00000000”; whenothers=out_row=“11111111”;out_r=“00000000”;out_g=“00000000”; end case;elseif(win=1)then -successc

47、ase count_sweep is -heartwhen7=out_row=“01111111”;out_r=“00100010”;out_g=“00000000”; when6=out_row=“10111111”;out_r=“01110111”;out_g=“00000000”; when5=out_row=“11011111”;out_r=“01111111”;out_g=“00000000”; when4=out_row=“11101111”;out_r=“01111111”;out_g=“00000000”; when3=out_row=“11110111”;out_r=“001

48、11110”;out_g=“00000000”; when2=out_row=“11111011”;out_r=“00011100”;out_g=“00000000”; when1=out_row=“11111101”;out_r=“00001000”;out_g=“00000000”; when0=out_row=“11111110”;out_r=“00000000”;out_g=“00000000”; whenothers=out_row=“11111111”;out_r=“00000000”;out_g=“00000000”; end case;elseif(round=0) thenc

49、ase count_sweep is -maze0 when0=out_row=“01111111”;out_r=“11111111”;out_g=“00000000”; when1=out_row=“10111111”;out_r=“00111000”;out_g=“00000000”; when2=out_row=“11011111”;out_r=“10100011”;out_g=“00000000”; when3=out_row=“11101111”;out_r=“10101010”;out_g=“00000000”; when4=out_row=“11110111”;out_r=“10101010”;out_g=“00000000”;简易

温馨提示

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

最新文档

评论

0/150

提交评论