猫和老鼠游戏实验报告

数字电路综合

实验报告

信息与通信工程学院

班级:2009211120班

姓名: 李 川

学号: 09210591

题目:经典数学游戏

一.任务要求

实验内容:一个人要将1只狗,1只猫,1只老鼠渡过河,独木舟一次只

能装载和一只动物,但猫和狗不能单独在一起,而猫和老鼠也不能友好相处,试模拟这个人将三只动物安全渡过河的过程。 用发光二极管亮点的移动模拟独木舟渡河的过程,选中渡河的动物及两岸的动物都应有显示,若选错应有报警显示,且游戏失败,按复位键游戏重新开始。当三只动物均安全度过河时,游戏成功,并显示此次游戏独木舟往返渡河的次数。提高要求:游戏难度可设置,选错动物允许有一次修改机会。

二.系统设计

设计思路:用4个按钮分别用来选择人,狗,猫,鼠,8个LED来表示

人和动物的状态,左边4个代表左岸状态,右边4个代表右岸状态,船用点阵上的LED灯表示,灯右移代表船从左岸划到右岸,左移代表船从右岸划到左岸,失败和成功另外用点阵上的2个点表示。 总体框图及分块设计:

系统结构总框

系统结构图(模块划分和传递关系)

逻辑划分框图

MDS图

控制逻辑图(画在预习报告中,无法复制,截屏)

三.仿真波形及仿真分析

2ms时钟分频仿真图,clk1周期为1ms,是自己所需的,证明计算的分频的数

字正确,4Hz的clk2周期太长,就不进行仿真

数码管的仿真图,in:num,out:

step

模拟渡河的一步(错误的一步,报错fail=1)

复位,reset=1,pl=‘1111’,pr=‘0000’,各自复位

仿真图后面随便乱加的,因为我觉得此实验仿真过程较为复杂,还不如直接下载到板子上来找问题方便直接,故仿真图很粗糙。

四.源程序

--过河游戏--

--顶层模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity gh1 is

port( clock: in std_logic; --时钟信号,50MHz mank,dogk,catk,ratk: in std_logic; --人,狗,猫,老鼠的开关信号 enterk: in std_logic; --确认开关信号 resetk: in std_logic; --复位开关信号 pl,pr : out std_logic_vector(3 downto 0); --河两岸动物的状态 boat : out std_logic_vector(13 downto 0); --船灯信号 lose,win : out std_logic; --失败、成功的信号 steph,stepl : out std_logic_vector(6 downto 0));--数码管的驱动信号 end;

architecture jg of gh1 is component fenpin --调用分频器模块 port( cp: in std_logic; cp1,cp2:out std_logic ) ; end component; component fangdou --调用防抖动模块。 port( clk,key : in std_logic; q : out std_logic); end component; component shumaguan --调用译码显示模块。

port( num : in std_logic_vector(3 downto 0); step : out std_logic_vector(6 downto 0)); end component; component guohe --调用过河控制模块。 port( clk,clk1 : in std_logic; man,dog,cat,rat : in std_logic; enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0); counth,countl : out std_logic_vector(3 downto 0); boats : out std_logic_vector(13 downto 0); fail,success : out std_logic); end component;

signal temp1,temp2,temp3,c1,c2 : std_logic; signal temp4,temp5,temp6 : std_logic;

signal coh,col : std_logic_vector(3 downto 0);

begin u1 : fenpin port map(clock,c1,c2); u2 : fangdou port map(c1,mank,temp1); u3 : fangdou port map(c1,dogk,temp2); u4 : fangdou port map(c1,catk,temp3); u5 : fangdou port map(c1,ratk,temp4); u6 : fangdou port map(c1,enterk,temp5); u7 : fangdou port map(c1,resetk,temp6); u8 : guohe map(c1,c2,temp1,temp2,temp3,temp4,temp5,temp6,pl,pr,coh,col,boat,lose,win); u9 : shumaguan port map(coh,steph); u10: shumaguan port map(col,stepl); end jg; --防抖模块 library ieee;

use ieee.std_logic_1164.all; entity fangdou is

port(clk : in std_logic; --时钟信号,1 kHz。 key : in std_logic; --有抖动的开关信号。

q : out std_logic); --防抖动电路输出的无抖动信号。 end;

architecture fangdou1 of fangdou is signal cp : std_logic;

signal jsp : integer range 0 to 3; begin

port

process(clk,cp) begin

if(clk'event and clk='0')then if key='1'then if jsp=3 then jsp

jsp

if jsp=1 then cp

end process; end;

--分频模块 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity fenpin is port(cp : in std_logic; --时钟信号,50MHz cp1,cp2 : out std_logic); --1 kHz、2.5 Hz 的信号 end fenpin; architecture struct of fenpin is signal clk1,clk2,clk3 : std_logic; signal temp : std_logic_vector(6 downto 0); signal temp1 : std_logic_vector(8 downto 0); signal temp2 : std_logic_vector(8 downto 0); begin fp1:process(cp) begin

if rising_edge(cp) then if(temp="1100011") then clk1

else temp

fp2:process(clk1) begin

if rising_edge(clk1) then if(temp1="111101111") then clk2

end process fp2;

fp3:process(clk2) begin

if rising_edge(clk2) then if(temp2="110001111") then clk3

end process fp3;

cp1

--过河控制模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity guohe is

port( clk,clk1:in std_logic; man,dogman,dog,cat,rat : in std_logic; 关动作信号 enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0);

--人、狗、猫和鼠的开--确认开关信号。 --复位开关信号。

--河两岸动物的状态。

counth,countl : out std_logic_vector(3 downto 0); --过河次数。 boats : out std_logic_vector(13 downto 0); --船灯信号。 fail,success : out std_logic); end guohe;

architecture struct of guohe is

signal ch,cl : std_logic_vector(3 downto 0); signal state : std_logic_vector(3 downto 0); signal enable : std_logic; signal river,river1 : std_logic; signal side : std_logic;

signal boat : std_logic_vector(13 downto 0); signal first : std_logic;

signal ms,ds,cs,rs : std_logic; begin

p1 :process(clk) begin

if(rising_edge(clk)) then if(reset='1') then state

if( river='0' and river1='0' ) then if(enable='0') then if(man='1') then state(3)

if(dog='1') then

state(2)

--成功、警告信号。 --复位信号有效。 --右边状态全为'0',同时--若不处于运输过程。 --按下表示人的开关。 --人的状态改变。

end if;

if(cat='1') then

state(1)

if(rat='1') then

state(0)

if(enter='1') then --对过河次数的处理。 if(cl="1001") then if(ch="1001") then

ch

--若过河次数的高位也计到9,则判为失败。 else

ch

cl

side

--失败和成功的判断。 if (ms='0') then

fail

elsif(ds='1' and state(3)='0' and state(2)='1')then fail

elsif(cs='1' and state(3)='1' and state(1)='0')then fail

elsif(cs='1' and state(3)='0' and state(1)='1')then fail

elsif(rs='1' and state(3)='1' and state(0)='0')then fail

elsif(rs='1' and state(3)='0' and state(0)='1')then fail

fail

--有确认信号。

--人没有上船,过河失败。

fail

fail

elsif(state="1001" or state="1100" or state="0011" or state="0110" or state="0111" or state="1000") then fail

if(state="1111" ) then success

ms

--运输过程。 else

if(side='1' and boat(0)='1')then river1

elsif(side='0' and boat(2)='1')then river1

end process p1;

p2 :process(clk1,cl,ch) begin

if(cl

if (rising_edge(clk1)) then if (river1='0') then if (enable='0') then if (side='0') then boat

elsif(side='1')then

boat

boat

--若从左往右运输且右边的船灯已--若从右往左运输且左边的船灯已 --第一次运输开始前。 --左边的船灯 --人在左边。 --左边的船灯

if (side='1') then --从左往右运输。 boat(0)

boat(2)

boat(1)

end process p2;

p3 :process(clk1,first) begin

if(first='0')then --初始状态。 for i in 0 to 3 loop

pl(i)

if(rising_edge(clk1))then

if(side='1' and boat(2)= '1')then --从左往右运输且左边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

elsif(side='1' and boat(0)= '1')then

--从左往右运输且右边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(0)= '1')then

--从右往左运输且右边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(2)= '1')then

--从右往左运输且左边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

end process p3;

counth

--数码显示模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity guohe is

port( clk,clk1:in std_logic; man,dogman,dog,cat,rat : in std_logic; 关动作信号 enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0); counth,countl : out std_logic_vector(3 downto 0); boats : out std_logic_vector(13 downto 0); fail,success : out std_logic); end guohe;

architecture struct of guohe is

signal ch,cl : std_logic_vector(3 downto 0); signal state : std_logic_vector(3 downto 0); signal enable : std_logic; signal river,river1 : std_logic; signal side : std_logic;

--人、狗、猫和鼠的开--确认开关信号。 --复位开关信号。

--河两岸动物的状态。 --过河次数。 --船灯信号。 --成功、警告信号。

signal boat : std_logic_vector(13 downto 0); signal first : std_logic;

signal ms,ds,cs,rs : std_logic; begin

p1 :process(clk) begin

if(rising_edge(clk)) then if(reset='1') then state

if( river='0' and river1='0' ) then if(enable='0') then if(man='1') then

state(3)

ms

if(dog='1') then

state(2)

if(cat='1') then

state(1)

if(rat='1') then

state(0)

--复位信号有效。 --右边状态全为'0',同时

--若不处于运输过程。 --按下表示人的开关。

--人的状态改变。

if(enter='1') then --对过河次数的处理。 if(cl="1001") then if(ch="1001") then

ch

--若过河次数的高位也计到9,则判为失败。 else

ch

cl

side

--失败和成功的判断。 if (ms='0') then

fail

elsif(ds='1' and state(3)='0' and state(2)='1')then fail

elsif(cs='1' and state(3)='1' and state(1)='0')then fail

elsif(cs='1' and state(3)='0' and state(1)='1')then fail

elsif(rs='1' and state(3)='1' and state(0)='0')then fail

elsif(rs='1' and state(3)='0' and state(0)='1')then fail

fail

fail

fail

elsif(state="1001" or state="1100" or state="0011" or state="0110" or state="0111" or state="1000") then fail

if(state="1111" ) then success

--有确认信号。 --人没有上船,过河失败。

ms

--运输过程。 else

if(side='1' and boat(0)='1')then river1

elsif(side='0' and boat(2)='1')then river1

end process p1;

p2 :process(clk1,cl,ch) begin

if(cl

if (rising_edge(clk1)) then if (river1='0') then if (enable='0') then if (side='0') then boat

elsif(side='1')then

boat

boat

if (side='1') then boat(0)

boat(2)

boat(1)

--第一次运输开始前。 --左边的船灯 --人在左边。 --左边的船灯 --从左往右运输。 -- 船灯从左往右依次亮。

end if; end if; end if; end if;

end process p2;

p3 :process(clk1,first) begin

if(first='0')then --初始状态。 for i in 0 to 3 loop

pl(i)

if(rising_edge(clk1))then

if(side='1' and boat(2)= '1')then --从左往右运输且左边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

elsif(side='1' and boat(0)= '1')then

--从左往右运输且右边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(0)= '1')then

--从右往左运输且右边的船灯亮,即运输刚开始。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(2)= '1')then

--从右往左运输且左边的船灯亮,即运输结束。 for i in 0 to 3 loop

if(state(i)= '0')then pl(i)

pl(i)

end process p3;

counth

五.功能说明

六.元器件清单及资源利用情况 元器件清单:

LED灯:8个 按钮: 6个 七段数码管 点阵

资源利用情况:

左右岸动物均有表示,选中的动物灯熄灭

点阵点的移动代表船的渡河动作 成功或失败均有提示

船每过河一次,数码管显示+1

任何时候按下复位键,游戏重新开始

七.故障及问题分析

编译时,考虑最多的是过河的逻辑,没有考虑太多的与硬件的结合编程,到第三次检查时最重要的过河逻辑也没有编出来,当然无仿真图可言,后面是自己在网上找的一段代码,虽然起先编译未能通过,但问题不大,只用改改些许地方就行了,他采用的是if嵌套,套了7,8层if,起先看这段代码看不懂,后面把每个if和end if对应起来打印出来,再仔细想了几个小时才弄明白。

最初仿真时,因为自己过河动作的频率较低,故所需仿真的时间较长。得1S左右吧,仿真时发现总是到49%时总是不动了,后来才想到由于自己输入的是50MHz的频率,而自己需要的频率又很小,计算机进行此仿真会有大量的计算,导致仿真过慢,这个问题老师第一节课可能也说过,自己没注意。后来又以为如果要仿真就得改代码,故进行各个模块的仿真时都是另建工程再改代码进行仿真,而且忘保存了,不知道报告需要仿真图,后来才发现模块之间的信号是可以进行仿真的,可为时已晚。

进行下载时,有一次下载完后按按钮总没有反应,后面经同学提醒才知道有个按钮得按下,至于这个按钮的作用,不甚了解。 八.总结和结论 此次数电综合实验虽然不是自己完全自己独立完成(上网找了代码)的,但自己仍然学到了不少东西,一是熟悉了VHDL语言,对VHDL进行逻辑电路的结构方式也了解更深,特别是对process的理解和component的应用。另外,也因为此次实验只有自己选这一个题目,很多具体逻辑问题和实际问题都只有靠自己解决,问同学只能解决一部分,真正要完全解决只有靠自己,因此自己也得到了不少锻炼。但是自己也注意到自己编程还是没有考虑很多关于硬件的问题,更多的只是注意软件,这个自己后面还得好好锻炼。另外,对于状态机的认识也不够,希望老师在以后授课时可以让同学们真正学到怎么设计状态机,怎么利用状态机来进行编译等。

数字电路综合

实验报告

信息与通信工程学院

班级:2009211120班

姓名: 李 川

学号: 09210591

题目:经典数学游戏

一.任务要求

实验内容:一个人要将1只狗,1只猫,1只老鼠渡过河,独木舟一次只

能装载和一只动物,但猫和狗不能单独在一起,而猫和老鼠也不能友好相处,试模拟这个人将三只动物安全渡过河的过程。 用发光二极管亮点的移动模拟独木舟渡河的过程,选中渡河的动物及两岸的动物都应有显示,若选错应有报警显示,且游戏失败,按复位键游戏重新开始。当三只动物均安全度过河时,游戏成功,并显示此次游戏独木舟往返渡河的次数。提高要求:游戏难度可设置,选错动物允许有一次修改机会。

二.系统设计

设计思路:用4个按钮分别用来选择人,狗,猫,鼠,8个LED来表示

人和动物的状态,左边4个代表左岸状态,右边4个代表右岸状态,船用点阵上的LED灯表示,灯右移代表船从左岸划到右岸,左移代表船从右岸划到左岸,失败和成功另外用点阵上的2个点表示。 总体框图及分块设计:

系统结构总框

系统结构图(模块划分和传递关系)

逻辑划分框图

MDS图

控制逻辑图(画在预习报告中,无法复制,截屏)

三.仿真波形及仿真分析

2ms时钟分频仿真图,clk1周期为1ms,是自己所需的,证明计算的分频的数

字正确,4Hz的clk2周期太长,就不进行仿真

数码管的仿真图,in:num,out:

step

模拟渡河的一步(错误的一步,报错fail=1)

复位,reset=1,pl=‘1111’,pr=‘0000’,各自复位

仿真图后面随便乱加的,因为我觉得此实验仿真过程较为复杂,还不如直接下载到板子上来找问题方便直接,故仿真图很粗糙。

四.源程序

--过河游戏--

--顶层模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity gh1 is

port( clock: in std_logic; --时钟信号,50MHz mank,dogk,catk,ratk: in std_logic; --人,狗,猫,老鼠的开关信号 enterk: in std_logic; --确认开关信号 resetk: in std_logic; --复位开关信号 pl,pr : out std_logic_vector(3 downto 0); --河两岸动物的状态 boat : out std_logic_vector(13 downto 0); --船灯信号 lose,win : out std_logic; --失败、成功的信号 steph,stepl : out std_logic_vector(6 downto 0));--数码管的驱动信号 end;

architecture jg of gh1 is component fenpin --调用分频器模块 port( cp: in std_logic; cp1,cp2:out std_logic ) ; end component; component fangdou --调用防抖动模块。 port( clk,key : in std_logic; q : out std_logic); end component; component shumaguan --调用译码显示模块。

port( num : in std_logic_vector(3 downto 0); step : out std_logic_vector(6 downto 0)); end component; component guohe --调用过河控制模块。 port( clk,clk1 : in std_logic; man,dog,cat,rat : in std_logic; enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0); counth,countl : out std_logic_vector(3 downto 0); boats : out std_logic_vector(13 downto 0); fail,success : out std_logic); end component;

signal temp1,temp2,temp3,c1,c2 : std_logic; signal temp4,temp5,temp6 : std_logic;

signal coh,col : std_logic_vector(3 downto 0);

begin u1 : fenpin port map(clock,c1,c2); u2 : fangdou port map(c1,mank,temp1); u3 : fangdou port map(c1,dogk,temp2); u4 : fangdou port map(c1,catk,temp3); u5 : fangdou port map(c1,ratk,temp4); u6 : fangdou port map(c1,enterk,temp5); u7 : fangdou port map(c1,resetk,temp6); u8 : guohe map(c1,c2,temp1,temp2,temp3,temp4,temp5,temp6,pl,pr,coh,col,boat,lose,win); u9 : shumaguan port map(coh,steph); u10: shumaguan port map(col,stepl); end jg; --防抖模块 library ieee;

use ieee.std_logic_1164.all; entity fangdou is

port(clk : in std_logic; --时钟信号,1 kHz。 key : in std_logic; --有抖动的开关信号。

q : out std_logic); --防抖动电路输出的无抖动信号。 end;

architecture fangdou1 of fangdou is signal cp : std_logic;

signal jsp : integer range 0 to 3; begin

port

process(clk,cp) begin

if(clk'event and clk='0')then if key='1'then if jsp=3 then jsp

jsp

if jsp=1 then cp

end process; end;

--分频模块 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity fenpin is port(cp : in std_logic; --时钟信号,50MHz cp1,cp2 : out std_logic); --1 kHz、2.5 Hz 的信号 end fenpin; architecture struct of fenpin is signal clk1,clk2,clk3 : std_logic; signal temp : std_logic_vector(6 downto 0); signal temp1 : std_logic_vector(8 downto 0); signal temp2 : std_logic_vector(8 downto 0); begin fp1:process(cp) begin

if rising_edge(cp) then if(temp="1100011") then clk1

else temp

fp2:process(clk1) begin

if rising_edge(clk1) then if(temp1="111101111") then clk2

end process fp2;

fp3:process(clk2) begin

if rising_edge(clk2) then if(temp2="110001111") then clk3

end process fp3;

cp1

--过河控制模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity guohe is

port( clk,clk1:in std_logic; man,dogman,dog,cat,rat : in std_logic; 关动作信号 enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0);

--人、狗、猫和鼠的开--确认开关信号。 --复位开关信号。

--河两岸动物的状态。

counth,countl : out std_logic_vector(3 downto 0); --过河次数。 boats : out std_logic_vector(13 downto 0); --船灯信号。 fail,success : out std_logic); end guohe;

architecture struct of guohe is

signal ch,cl : std_logic_vector(3 downto 0); signal state : std_logic_vector(3 downto 0); signal enable : std_logic; signal river,river1 : std_logic; signal side : std_logic;

signal boat : std_logic_vector(13 downto 0); signal first : std_logic;

signal ms,ds,cs,rs : std_logic; begin

p1 :process(clk) begin

if(rising_edge(clk)) then if(reset='1') then state

if( river='0' and river1='0' ) then if(enable='0') then if(man='1') then state(3)

if(dog='1') then

state(2)

--成功、警告信号。 --复位信号有效。 --右边状态全为'0',同时--若不处于运输过程。 --按下表示人的开关。 --人的状态改变。

end if;

if(cat='1') then

state(1)

if(rat='1') then

state(0)

if(enter='1') then --对过河次数的处理。 if(cl="1001") then if(ch="1001") then

ch

--若过河次数的高位也计到9,则判为失败。 else

ch

cl

side

--失败和成功的判断。 if (ms='0') then

fail

elsif(ds='1' and state(3)='0' and state(2)='1')then fail

elsif(cs='1' and state(3)='1' and state(1)='0')then fail

elsif(cs='1' and state(3)='0' and state(1)='1')then fail

elsif(rs='1' and state(3)='1' and state(0)='0')then fail

elsif(rs='1' and state(3)='0' and state(0)='1')then fail

fail

--有确认信号。

--人没有上船,过河失败。

fail

fail

elsif(state="1001" or state="1100" or state="0011" or state="0110" or state="0111" or state="1000") then fail

if(state="1111" ) then success

ms

--运输过程。 else

if(side='1' and boat(0)='1')then river1

elsif(side='0' and boat(2)='1')then river1

end process p1;

p2 :process(clk1,cl,ch) begin

if(cl

if (rising_edge(clk1)) then if (river1='0') then if (enable='0') then if (side='0') then boat

elsif(side='1')then

boat

boat

--若从左往右运输且右边的船灯已--若从右往左运输且左边的船灯已 --第一次运输开始前。 --左边的船灯 --人在左边。 --左边的船灯

if (side='1') then --从左往右运输。 boat(0)

boat(2)

boat(1)

end process p2;

p3 :process(clk1,first) begin

if(first='0')then --初始状态。 for i in 0 to 3 loop

pl(i)

if(rising_edge(clk1))then

if(side='1' and boat(2)= '1')then --从左往右运输且左边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

elsif(side='1' and boat(0)= '1')then

--从左往右运输且右边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(0)= '1')then

--从右往左运输且右边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(2)= '1')then

--从右往左运输且左边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

end process p3;

counth

--数码显示模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity guohe is

port( clk,clk1:in std_logic; man,dogman,dog,cat,rat : in std_logic; 关动作信号 enter : in std_logic; reset : in std_logic; pl,pr : out std_logic_vector(3 downto 0); counth,countl : out std_logic_vector(3 downto 0); boats : out std_logic_vector(13 downto 0); fail,success : out std_logic); end guohe;

architecture struct of guohe is

signal ch,cl : std_logic_vector(3 downto 0); signal state : std_logic_vector(3 downto 0); signal enable : std_logic; signal river,river1 : std_logic; signal side : std_logic;

--人、狗、猫和鼠的开--确认开关信号。 --复位开关信号。

--河两岸动物的状态。 --过河次数。 --船灯信号。 --成功、警告信号。

signal boat : std_logic_vector(13 downto 0); signal first : std_logic;

signal ms,ds,cs,rs : std_logic; begin

p1 :process(clk) begin

if(rising_edge(clk)) then if(reset='1') then state

if( river='0' and river1='0' ) then if(enable='0') then if(man='1') then

state(3)

ms

if(dog='1') then

state(2)

if(cat='1') then

state(1)

if(rat='1') then

state(0)

--复位信号有效。 --右边状态全为'0',同时

--若不处于运输过程。 --按下表示人的开关。

--人的状态改变。

if(enter='1') then --对过河次数的处理。 if(cl="1001") then if(ch="1001") then

ch

--若过河次数的高位也计到9,则判为失败。 else

ch

cl

side

--失败和成功的判断。 if (ms='0') then

fail

elsif(ds='1' and state(3)='0' and state(2)='1')then fail

elsif(cs='1' and state(3)='1' and state(1)='0')then fail

elsif(cs='1' and state(3)='0' and state(1)='1')then fail

elsif(rs='1' and state(3)='1' and state(0)='0')then fail

elsif(rs='1' and state(3)='0' and state(0)='1')then fail

fail

fail

fail

elsif(state="1001" or state="1100" or state="0011" or state="0110" or state="0111" or state="1000") then fail

if(state="1111" ) then success

--有确认信号。 --人没有上船,过河失败。

ms

--运输过程。 else

if(side='1' and boat(0)='1')then river1

elsif(side='0' and boat(2)='1')then river1

end process p1;

p2 :process(clk1,cl,ch) begin

if(cl

if (rising_edge(clk1)) then if (river1='0') then if (enable='0') then if (side='0') then boat

elsif(side='1')then

boat

boat

if (side='1') then boat(0)

boat(2)

boat(1)

--第一次运输开始前。 --左边的船灯 --人在左边。 --左边的船灯 --从左往右运输。 -- 船灯从左往右依次亮。

end if; end if; end if; end if;

end process p2;

p3 :process(clk1,first) begin

if(first='0')then --初始状态。 for i in 0 to 3 loop

pl(i)

if(rising_edge(clk1))then

if(side='1' and boat(2)= '1')then --从左往右运输且左边的船灯亮,即运输刚开始。

for i in 0 to 3 loop if(state(i)= '0')then pl(i)

pl(i)

elsif(side='1' and boat(0)= '1')then

--从左往右运输且右边的船灯亮,即运输结束。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(0)= '1')then

--从右往左运输且右边的船灯亮,即运输刚开始。 for i in 0 to 3 loop if(state(i)= '0')then pr(i)

pr(i)

elsif(side='0' and boat(2)= '1')then

--从右往左运输且左边的船灯亮,即运输结束。 for i in 0 to 3 loop

if(state(i)= '0')then pl(i)

pl(i)

end process p3;

counth

五.功能说明

六.元器件清单及资源利用情况 元器件清单:

LED灯:8个 按钮: 6个 七段数码管 点阵

资源利用情况:

左右岸动物均有表示,选中的动物灯熄灭

点阵点的移动代表船的渡河动作 成功或失败均有提示

船每过河一次,数码管显示+1

任何时候按下复位键,游戏重新开始

七.故障及问题分析

编译时,考虑最多的是过河的逻辑,没有考虑太多的与硬件的结合编程,到第三次检查时最重要的过河逻辑也没有编出来,当然无仿真图可言,后面是自己在网上找的一段代码,虽然起先编译未能通过,但问题不大,只用改改些许地方就行了,他采用的是if嵌套,套了7,8层if,起先看这段代码看不懂,后面把每个if和end if对应起来打印出来,再仔细想了几个小时才弄明白。

最初仿真时,因为自己过河动作的频率较低,故所需仿真的时间较长。得1S左右吧,仿真时发现总是到49%时总是不动了,后来才想到由于自己输入的是50MHz的频率,而自己需要的频率又很小,计算机进行此仿真会有大量的计算,导致仿真过慢,这个问题老师第一节课可能也说过,自己没注意。后来又以为如果要仿真就得改代码,故进行各个模块的仿真时都是另建工程再改代码进行仿真,而且忘保存了,不知道报告需要仿真图,后来才发现模块之间的信号是可以进行仿真的,可为时已晚。

进行下载时,有一次下载完后按按钮总没有反应,后面经同学提醒才知道有个按钮得按下,至于这个按钮的作用,不甚了解。 八.总结和结论 此次数电综合实验虽然不是自己完全自己独立完成(上网找了代码)的,但自己仍然学到了不少东西,一是熟悉了VHDL语言,对VHDL进行逻辑电路的结构方式也了解更深,特别是对process的理解和component的应用。另外,也因为此次实验只有自己选这一个题目,很多具体逻辑问题和实际问题都只有靠自己解决,问同学只能解决一部分,真正要完全解决只有靠自己,因此自己也得到了不少锻炼。但是自己也注意到自己编程还是没有考虑很多关于硬件的问题,更多的只是注意软件,这个自己后面还得好好锻炼。另外,对于状态机的认识也不够,希望老师在以后授课时可以让同学们真正学到怎么设计状态机,怎么利用状态机来进行编译等。


相关文章

  • 心理学第四章课后习题
  • 第四章 课后习题 一.单项选择题: ( C )1.区分操作条件反应与经典条件反应的正确标准是__________. A条件反应是否受到直接强化 B新的S-R联结是否形成 C强化物是否出现在新的反应前 D以上都是 ( A )2.基于观众的条件 ...查看


  • 小班游戏活动何柳:小老鼠上灯台
  • 小班游戏活动:快乐的小老鼠 黄冈市实验幼儿园 何柳 活动背景: 小班幼儿对小动物有一种很特殊的感情,并表现出莫大的关心与好奇,他们喜爱模仿各种小动物并很快进入角色中.我发现我们班幼儿对动画片<猫和老鼠>很关注,说起故事中的小老鼠 ...查看


  • 心理学家说:记忆力不好就去做梦吧
  • 2011年10月27日10:16腾讯读书[微博]我要评论(0) 字号:T|T 文章摘自:<我知道你不知道的自己在想什么> 作者:果壳 出版社:浙江大学出版社 版次:2011年10月第一版 本书简介:你的名字能透露什么特别信息?闹 ...查看


  • 我自信 我快乐
  • 我自信 我快乐 活动目标 1. 认识自信的重要性. 2. 通过小组合作,发挥团体的力量,注重学生的感悟.体验.分享. 3.通过给自己为别人找优点,全面提高学生的自信,并学会在日常的生活中积极面对问题和困难. 活动重点: 1.认识自信的重要性 ...查看


  • 难忘那些游戏
  • 湖北荆门沙洋县实验小学五年级三班陈霄宇 在我玩的游戏中,让我最难忘的还是那些令人既轻松又愉快的游戏,我感到永远玩不够. 老鼠偷油 它的玩法是,先选出一只猫,剩下的人都是老鼠.游戏开始了,老鼠们一溜烟似地跑进了窝,(所谓窝,就是一条界线里面的 ...查看


  • [关于合作的作文]关于合作的作文700字
  • 今天体育大课间,我们班做了一个名叫"千千结"的小游戏.这个游戏十几个人先围在一起围成个圈,所有人手拉手,记住左右手的人,然后到处跑,换位子,当说"停"时,在左右手和之前的人拉在一起,被当作" ...查看


  • 幼儿园教案小班数学活动 认识前后
  • 教案 幼儿园小班数学活动 认识前后 活动目标: 一.学习以自身及客体为中心,认识和区分前后.二.通过活动使幼儿形成初步的空间概念,培养幼儿对数学活动的兴趣.三.学习正确使用方位词:前.后.能用方位词正确完整地表述,并读准字音. 准备活动: ...查看


  • 惠安县实验小学605班自编童谣
  • 惠安县实验小学605班的同学们创作了很好听的闽南语歌谣.歌谣注意押韵,内容有趣味.大家念后,请多提意见. 妈妈真辛苦 谢可欣 年兜歌 曾海婷 年未兜,代志真正厚. 炊糕炊粿炊菜包,做衫做裤穿年兜. 孩子四处走,闹我忙啊乱糟糟. [注]①厚: ...查看


  • 关于DNA纳米技术
  • 关于DNA纳米技术,我不得不说的话: DAN纳米技术是在上世纪末随着纳米技术的兴起而逐渐热起来的,并且当时我的硕士课题也涉及到了DNA纳米技术,并且也做了点相关工作. DNA纳米技术是利用DNA分子之间的互补性以及可控性,因为其分子结构介于 ...查看


热门内容