猫和老鼠游戏实验报告.docx
《猫和老鼠游戏实验报告.docx》由会员分享,可在线阅读,更多相关《猫和老鼠游戏实验报告.docx(24页珍藏版)》请在课桌文档上搜索。
1、信息与通信工程学院班级:2009211120班姓名:李川学号:09210591题目:经典数学游戏一.任务要求实验内容:一个人要将1只狗,1只猫,1只老鼠渡过河,独木舟一次只能装载和一只动物,但猫和狗不能单独在一起,而猫和老鼠也不能友好相处,试模拟这个人将三只动物安全渡过河的过程。用发光二极管亮点的移动模拟独木舟渡河的过程,选中渡河的动物及两岸的动物都应有显示,若选错应有报警显示,且游戏失败,按复位键游戏重新开始。当三只动物均安全度过河时,游戏成功,并显示此次游戏独木舟往返渡河的次数。提高要求:游戏难度可设置,选错动物允许有一次修改机会。二.系统设计设计思路:用4个按钮分别用来选择人,狗,猫,鼠
2、,8个LED来表示人和动物的状态,左边4个代表左岸状态,右边4个代表右岸状态,船用点阵上的LED灯表示,灯右移代表船从左岸划到右岸,左移代表船从右岸划到左岸,失败和成功另外用点阵上的2个点表示。总体框图及分块设计:系统结构总框系统结构图(模块划分和传递关系)逻辑划分框图MDS图控制逻辑图(画在预习报告中,无法复制,截屏)三.仿真波形及仿真分析Dps163.84us327.8us491.52us655us819.2us98394us1.邛ms1.31ms1.4Jms1.64ms1.8as1.97m;17.55ns2ms时钟分频仿真图,clkl周期为lms,是自己所需的,证明计算的分频的数字正确,
3、4Hz的clk2周期太长,就不进行仿真ns420.0ns440.0ns460.0ns480.0ns500.pns520.0ns540.pnsManeValueat16.98 nsmanB 1catB 1elkB 0clklB 0dogB 0enterB 1 plB Hll PrB OooOratB 0rstB 0successB 0failB 0court .BO)PS335.542671.09 ms1.01 s16.975 ns-TnTT0101模拟渡河的一步(错误的一步,报错fail=l),f.pJU.UJNlWJYCll3J.,NfW*.I80.RSA1V、Valueat-1J!16.9
4、8ns之之*88之331B1BOBOBOB1BHllBOOOOBOBOBOBOOKn复位,reset=1,pl=111,pr=0000,各自复位仿真图后面随便乱加的,因为我觉得此实验仿真过程较为复杂,还不如直接下载到板子上来找问题方便直接,故仿真图很粗糙。四.源程序-过河游戏-libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entityghlisport(clock:instdOgic;-时钟信号,50MHzmank,dogk,catk,ratk:
5、instdOgic;-人,狗,猫,老鼠的开关信号enterk:instd_logic;-确认开关信号resetk:instd_logic;-复位开关信号pl,pr:outstdOgiC_VeCtor(3downtoO);-河两岸动物的状态boat:outstd_logic_vector(13downtoO);-船灯信号lose,win:outstd_logic;-失败、成功的信号steph,stepl:outstd_logic_vector(6downto0);-数码管的驱动信号-顶层模块end;architecturejgofghliscomponentfenpinport(cp:instd
6、_logic;cpl,cp2:outStdJogic);endcomponent;-调用分频器模块componentfangdouport(elk,key:inStdJogic;q:outstd_logic);endcomponent;-调用防抖动模块。componentshumaguan-调用译码显示模块。port(num:instd_logic_vector(3downto0);step:outstd_logic_vector(6downto0);endcomponent;componentguohe-调用过河控制模块。port(elk,elk1:instd_logic;man,dog,c
7、at,rat:inStdJogic;enter:inStdJogic;reset:instd_logic;pl,pr:outstd_logic_vector(3downtoO);counth,countl:outstd_logic_vector(3downtoO);boats:outstd_logic_vector(13downtoO);fail,success:outstdOgiC);endcomponent;signaltemp1,temp2,temp3,c1,c2:std_logic;signaltemp4,temp5,temp6:std_logic;signalcoh,col:std_
8、logic_vector(3downtoO);beginul:fenpinportmap(clock,cl,c2);u2:fangdouportmap(c1,mank,temp1);u3:fangdouportmap(c1,dogk,temp2);u4:fangdouportmap(c1,catk,temp3);u5:fangdouportmap(c1,ratk,temp4);u6:fangdouportmap(c1,enterk,temp5);u7:fangdouportmap(c1,resetk,temp6);u8:guoheportmap(cl,c2,temp1,temp2,temp3,
9、temp4,temp5,temp6,pl,pr,coh,col,boat,lose,win);u9:shumaguanportmap(coh,steph);ul:shumaguanportmap(col,stepl);endjg;-防抖模块libraryieee;useieee.std_logic_1164.all;entityfangdouisport(clk:instdOgic;-时钟信号,1kHz。key:inStdJogic;-有抖动的开关信号。q:outStdJogic);-防抖动电路输出的无抖动信号。end;architecturefangdou1offangdouissignal
10、cp:std_logic;signaljsp:integerrangeOto3;beginprocess(clk,cp)beginif(clk,eventandclk=,0)thenifkey=1,thenifjsp=3thenjsp=jsp;elsejsp=jsp+l;endif;ifjsp=lthencp-;elsecp=,0,;endif;elsejsp=O;endif;endif;q=cp;endprocess;end;-分频模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_
11、logic_unsigned.all;entityfenpinisport(cp:instd_logic;-时钟信号,50MHZcp1,cp2:outstdOgiC);-lkHz、2.5Hz的信号endfenpin;architecturestructoffenpinissignalclkl,clk2,clk3:StdJogic;signaltemp:std_logic_vector(6downtoO);signaltempi:std_logic_vector(8downtoO);signaltemp2:std_logic_vector(8downtoO);beginfpkprocess(cp
12、)beginifrising_edge(cp)thenif(temp=llOOO1,)thenclkl=notclkl;temp=0000000;elsetemp=temp+1;endif;endif;endprocessfp1;fp2:process(clkl)beginifrising_edge(clk1)thenif(templ=,11110111,)thenclk2=notclk2;templ=000000000;elsetempl=temp1+1;endif;endif;endprocessfp2;fp3:process(clk2)beginifrising_edge(clk2)th
13、enif(temp2=l1000111,)thenclk3=notclk3;temp2=000000000;elsetemp2=temp2+l;endif;endif;endprocessfp3;cpl=clk2;cp2=clk3;endstruct;-过河控制模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityguoheis-人、狗、猫和鼠的开-确认开关信号。-复位开关信号。河两岸动物的状态。port(clk,clkkinstdogic;man,dogman,dog,cat,rat:inS
14、tdJogic;关动作信号enter:inStdJogic;reset:instd_logic;pl,pr:outstd_logic_vector(3downtoO);counth,countl:outstd_logic_vector(3downto0);-过河次数。boats:outstd_logic_vector(13downto0);-船灯信号。fail,success:outstd_logic);endguohe;architecturestructofguoheissignalch,cl:std_logic_vector(3downto0);signalstate:std_logic
15、_vector(3downto0);signalenable:std_logic;signalriver,river1:std_logic;signalside:std_logic;signalboat:std_logic_vector(1:signalfirst:stdOgic;signalms,ds,cs,rs:std_logic;beginpl:process(clk)beginif(rising_edge(clk)thenif(reset=*1,)thenstate=OOOO*;左边状态全为T。fail=O;success=,O;enable=,O;ch=OOOO,;cl=OOOO;m
16、s=,0,;ds=O,;cs=O;rs=,O,;riverl=0,;side=,O;first=,O;elseif(river=,O,andriverl=10,)thenif(enable=,O,)thenif(man=l,)thenstate(3)=notstate(3);ms=notms;first=,;endif;if(dog-)thenstate(2)=notstate(2);ds=notds;first=,:-成功、警告信号。-复位信号有效。-右边状态全为0,同时-若不处于运输过程。-按下表示人的开关。-人的状态改变。endif;if(cat=l,)thenstate(1)=nots
17、tate(1);cs=notcs;first=;endif;if(rat=l,)thenstate(0)=notstate(0);rs=notrs;first=,;endif;-有确认信号。if(enter=,)then- -对过河次数的处理。if(cl=100()thenif(ch=n100,)thench=ch;cl=cl;fail=,1enable=,;- -若过河次数的高位也计到9,则判为失败。elsech=ch+l;cl=,0000;endif;elsecl=cl+l;endif;side=notside;river1=;- -失败和成功的判断。if(ms-0,)thenfail=1
18、,;enable=1;river1=,0,;-人没有上船,过河失败。- 人和动物在河的两边却同时上船的失败判断。elsif(ds=andstate(3)=,andstate(2)=0,)thenfail=r;enable=r;river1=,0;elsif(ds=andstate(3)=O,andstate(2),1)thenfail=1,ienable=*lriverl-0,;elsif(cs-andstate(3)=,andstate(1)=,O,)thenfail,l;enable=riverl-O;elsif(cs=,l,andstate(3)=O,andstate(l)-l,)the
19、nfail=r;enable=,l;riverl-0;elsif(rs-1andstate(3)=,l,andstate(O)=,O,)thenfail=1;enable=1;river1-0,;elsif(rs=andstate(3)=,O,andState(O)-)thenfail=r;enable=,r;riverl-0;elsif(dsandcs)=,thenfail=r;enable=I;riverl-0,;elsif(csandrs)=,thenfail=,lenable=,lriverl=,0;elsif(dsandrs)=,thenfail=r;enable=,l;river1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 猫和老鼠 游戏 实验 报告

链接地址:https://www.desk33.com/p-224935.html