职场文秘网

首页 > 入党材料 > 思想汇报 / 正文

EDA拔河游戏机课程设计

2021-01-21 03:02:26

 XXXXXX学院 课 程 设 计

  题

  目:EDA拔河游戏机课程设计

  作

 者:

 XXX

  专

 业:

  自动化

  班

 级:

 XXX

 学

 号:

  XXXXX

  指导老师:

 XXX

  2012年X月X日 主要内容、基本要求、主要参考资料等 主要内容:

 电子拔河游戏机是一种能容纳甲乙双方参赛游戏电路。由一排发光二极管表示拔河的“电子绳”。由甲乙双方通过按纽开关使发光二极管向一方的终点延伸,当延伸到某方的最后一个发光二极管时, 则该方获胜,连续比赛多局以定胜负。

  基本要求:

 1、设计一个能进行拔河游戏的电路。

 2、电路使用9个发光二极管,开机后只有中间一个发亮,此即拔河的中心点。

 3、游戏双方各持一个按钮,迅速地、不断地按动,产生脉冲,谁按得快,亮点就向谁的方向移动,每按一次,亮点移动一次。

 4、亮点移到任一方终端二极管时,这一方就获胜,此时双方按钮均无作用,输出保持,只有复位后才使亮点恢复到中心。

 5、用数码管显示获胜者的盘数。

  主要参考资料:

 [1] 潘松著.EDA技术实用教程(第二版). 北京:科学出版社,2005. [2] 康华光主编.电子技术基础 模拟部分. 北京:高教出版社,2006. [3] 阎石主编.数字电子技术基础. 北京:高教出版社,2003.

  一、总体设计思想 1.基本原理 由设计内容可知,需要一个十进制的计数器,用于对双方按钮的次数计数,并通过译码器显示在数码管上。设计要求用50MHz的频率,而设计用到的是1KHz的频率,所以要设计一个程序进行分频。显视控制部分设计要求在发光二极管上显示游戏状态,双方每按十次,亮点向先按十次移动一次,对脉冲进行计数,每十次移一位。需接入一个清零端,用于复位。将以上程序组装起来。

 2.设计框图 译码器 编码 电路

 选择 开关 整形 电路 可逆 计数器 控制电路

 图1. 拔河机游戏机框图

 二、设计步骤和调试过程 1、总体设计电路 总体电路图和仿真图如图(25)所示,由仿真图可知,此电路设计无误,可以实现按动A、B两个按键时,分别产生两个脉冲信号,经整形后分别加到可逆计数器上,可逆计数器输出的代码经译码器译码后驱动电平指示灯点亮并产生位移,当亮点移到任何一方终端后,由于控制电路的作用,使这一状态被锁定,双方按键产生的输入脉冲不起作用。如按动复位键C,亮点又回到中点位置,再次按C键则比赛又可重新开始。

 图2. 电路图 2、模块设计和相应模块程序 1.顶层文件 library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

 entity bahe is

 port(

  player1,player2:in std_logic; --玩家1,2输入

  clk_in:in std_logic;

  --clk_in(1MHZ)

  reset:in std_logic;

 --重置键

  row : out std_logic_vector(7 downto 0);

  col : out std_logic_vector(7 downto 0);

  led:out std_logic_vector(7 downto 0); --绳子

  cats:out std_logic_vector(6 downto 0); --比分

  q:out std_logic_vector(5 downto 0);

 --数码管控制

  mus:out std_logic);

  --蜂鸣输出 end bahe;

 architecture body_bahe of bahe is --分频模块

 component division

  port(

 clk_in:in std_logic;

  --1MHZ输入

 clk_100,clk_5,clk_1:out std_logic);--100HZ,5Hz,1HZ

  end component; --计数模块

  component count

  port(

  clk_1:in std_logic;

 --1HZ输入

 sw:in std_logic;

 --状态开关

 player1,player2:in std_logic; --选手输入

 sum1,sum2:out std_logic_vector(4 downto 0)); --计数结果输出

  end component; --比较模块

  component cmp

  port(

 clk_100:in std_logic; --100hz

 clk_1:in std_logic;

 --1hz

 sw:out std_logic;

 --状态开关输出

 reset:in std_logic;

 --重置

 start:in std_logic;

 --开始

 sum1,sum2:in std_logic_vector(4 downto 0);--计数结果输入

 music_begin:out std_logic;

  --音乐

 record1,record2:out std_logic_vector(1 downto 0);--比分输出

 lights:out std_logic_vector(2 downto 0));

 --拔河绳子显示

 end component; --音乐模块

  component music

  port(

 reset:in std_logic;

  --重置

  clk:in std_logic;

  --1MHz

  clk_5:in std_logic;

  --5hz

  music_begin:in std_logic;

  --音乐开始

  mus:out std_logic);

  end component; --译码模块

  component decode

 port(

 clk_in:in std_logic;

 --1mHZ

 record1,record2:in std_logic_vector(1 downto 0); --比分输入

 lights:in std_logic_vector(2 downto 0); --拔河绳子输入

 led:out std_logic_vector(7 downto 0); --输出到LED

 q:buffer std_logic_vector(5 downto 0);

 --数码管控制

 cats:out std_logic_vector(6 downto 0) --数码管显示比分

  );

 end component; --倒计时模块

 component daojishi

 port(

 clk_in,clk_1,reset:in std_logic;

 row : out std_logic_vector(7 downto 0);

  col : out std_logic_vector(7 downto 0);

 start: out std_logic

  );

 end component;

 --分频器输出

  signal clk_100,clk_5,clk_1:std_logic; --时钟信号

 --计数器输出

 signal sum1,sum2:std_logic_vector(4 downto 0);

 --计数结果

 --比较器输出

 signal sw:std_logic;

 --状态开关

 signal record1,record2:std_logic_vector(1 downto 0); --比分

 signal lights:std_logic_vector(2 downto 0);

 --绳子

 signal music_begin:std_logic;

 --解码器输出

 signal tmp_led:std_logic_vector(7 downto 0); --LED显示

 signal tmp_q:std_logic_vector(5 downto 0);

 --数码管控制

 signal

 tmp_cat:std_logic_vector(6 downto 0); --数码管显示比分

 --倒计时器输出

 signal tmp_start:std_logic;

  begin

  cats<=tmp_cat;

  q<=tmp_q;

  led<=tmp_led;

 div: division port map(clk_in=>clk_in,clk_100=>clk_100,clk_5=>clk_5,clk_1=>clk_1);

  cnt: count port map(

  clk_1=>clk_1,sw=>sw,player1=>player1,player2=>player2,

  sum1=>sum1,sum2=>sum2);

  com: cmp port map(

  clk_100=>clk_100,clk_1=>clk_1,sw=>sw,reset=>reset,

  start=>tmp_start,sum1=>sum1,sum2=>sum2,music_begin=>music_begin,

  record1=>record1,record2=>record2,lights=>lights);

  dec: decode port map(

  clk_in=>clk_in,record1=>record1,record2=>record2,

  lights=>lights,led=>tmp_led,q=>tmp_q,cats=>tmp_cat);

  mu:

 music port map(

  reset=>reset,clk=>clk_in,clk_5=>clk_5,

  music_begin=>music_begin,mus=>mus);

  dao: daojishi port map(

  clk_in=>clk_in,clk_1=>clk_1,reset=>reset,

  start=>tmp_start,col=>col,row=>row);

 end body_bahe; 2.CMP模块

 library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

 entity cmp is

 port(clk_100:in std_logic;

 --100HZ输入

 clk_1:in std_logic;

 --1HZ输入

  reset:in std_logic;

 --重置

 start:in std_logic;

 --开始

 sum1,sum2:in std_logic_vector(4 downto 0);

  --计数输入

 record1,record2:out std_logic_vector(1 downto 0); --比分输出

 music_begin:out std_logic;

  --音乐开始

 sw:out std_logic;

  --状态输出

 lights:out std_logic_vector(2 downto 0));

  --绳子状态

 end cmp;

 architecture body_cmp of cmp is

  signal tmp_record1:std_logic_vector(1 downto 0);

 --比分

 signal tmp_record2:std_logic_vector(1 downto 0);

 signal tmp:std_logic_vector(2 downto 0);

 --绳子状态

 signal tmp_sta:std_logic;

 --状态

 signal s1,s2:std_logic_vector(4 downto 0);

 --计数

  begin

 record1<=tmp_record1;

  record2<=tmp_record2;

  lights<=tmp;

  sw<=tmp_sta;

 process(clk_100)

  --判断比赛状态

  begin

 if(start='1') then

  if(clk_100'event and clk_100='1') then

 tmp_sta<='1';

  end if;

 end if;

  if(clk_100'event and clk_100='1') then

  --任意比分到3,比赛结束,开始播放音乐

  if(tmp_record1=“11“ or tmp_record2=“11“) then

 tmp_sta<='0';

  music_begin<='1';

  end if;

  if(tmp=“001“ or tmp=“111“) then

 --绳子到头,进入等待状态

 tmp_sta<='0';

 end if;

  if(reset='1') then

  --复位,状态归零

 tmp_sta<='0';

 music_begin<='0';

  end if;

 end if;

  end process;

 s1<=sum1;

  s2<=sum2;

  process(clk_1,reset)

 --控制绳子移位

  begin

 if(reset='1') then

 tmp<=“100“;

  --绳子初始状态为100

  tmp_record1<=“00“;

  tmp_record2<=“00“;

 else

  if(clk_1'event and clk_1='1') then

 if(tmp_sta='1') then

  if(s1>s2) then tmp<=tmp-'1';

 --绳子左移

  elsif(s1=s2) then tmp<=tmp;

  --绳子保持原状

  else tmp<=tmp+'1';

  --绳子右移

  end if;

 else

  if(tmp=“001“) then

  --绳子到左尽头,左计分器加1

 tmp_record1<=tmp_record1+'1';

 tmp<=“100“;

 elsif(tmp=“111“) then

 --绳子到右尽头,右记分器加1,

 tmp_record2<=tmp_record2+'1';

 tmp<=“100“;

  end if;

 end if;

 end if;

 end if;

  end process;

 end body_cmp; 3.COUT模块

 use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

 entity count is

 library IEEE; port(clk_1:in std_logic;

  --1HZ输入

  sw:in std_logic;

 --状态判断输入

 player1,player2:in std_logic;

  --选手输入

 sum1,sum2:out std_logic_vector(4 downto 0)); --计数输出

 end count;

 architecture body_count of count is

  signal p1,p2:std_logic_vector(4 downto 0);

  --计数输出

 begin

  sum1<=p1;

  sum2<=p2;

  process(player1,player2,sw,clk_1)

  begin

 if(sw='1') then

 --处于比赛状态

  if(clk_1='0') then

 if(player1'event and player1='1') then

  p1<=p1+'1';

 end if;

 if(player2'event and player2='1') then

  p2<=p2+'1';

 end if;

  else

  p1<=“00000“;

  p2<=“00000“;

  end if;

  --比赛状态结束

 else p1<=“00000“;

 p2<=“00000“;

 end if;

  end process;

 end body_count; 4.daojishi模块

 library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

 entity daojishi is

 port(clk_1,clk_in,reset: in std_logic;

 row : out std_logic_vector(7 downto 0);

 col : out std_logic_vector(7 downto 0);

 start : out std_logic); end daojishi;

 architecture body_daojishi of daojishi is

 type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);

 signal present_state:state:=s10;

  signal num:std_logic_vector(2 downto 0):=“000“;

  begin

  p3:process(clk_in)

  begin

  if clk_in'event and clk_in='1' then

 if num=“101“ then num<=“000“;

 else num<=num+1;

 case present_state is

 when s9=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01110100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s8=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01111100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s7=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01000000“;

  when “010“=> col<=“11101111“; row<=“01000000“;

  when “011“=> col<=“11110111“; row<=“01000000“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s6=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01111100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01011100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s5=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01110100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01011100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s4=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01110000“;

  when “010“=> col<=“11101111“; row<=“00010000“;

  when “011“=> col<=“11110111“; row<=“00010000“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s3=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01010100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s2=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01011100“;

  when “010“=> col<=“11101111“; row<=“01010100“;

  when “011“=> col<=“11110111“; row<=“01010100“;

  when “100“=> col<=“11111011“; row<=“01110100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when s1=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“00000000“;

  when “010“=> col<=“11101111“; row<=“00000000“;

  when “011“=> col<=“11110111“; row<=“00000000“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

  when s0=>

  case num is

  when “000“=> col<=“11111111“; row<=“11111111“;

  when “001“=> col<=“11011111“; row<=“01111100“;

  when “010“=> col<=“11101111“; row<=“01000100“;

  when “011“=> col<=“11110111“; row<=“01000100“;

  when “100“=> col<=“11111011“; row<=“01111100“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 when others=>

  case num is

  when “000“=> col<=“00000000“; row<=“00000000“;

  when “001“=> col<=“00000000“; row<=“00000000“;

  when “010“=> col<=“00000000“; row<=“00000000“;

  when “011“=> col<=“00000000“; row<=“00000000“;

  when “100“=> col<=“00000000“; row<=“00000000“;

  when others=> col<=“00000000“; row<=“00000000“;

  end case;

 end case;

 end if;

  end if;

  end process p3;

 p4:process(clk_1)

  begin

  if reset='1' then present_state<=s10;start<='0';

  else

 if clk_1'event and clk_1='1' then

  case present_state is

  when s10=> present_state<=s9;start<='0';

 when s9=> present_state<=s8;start<='0';

 when s8=> present_state<=s7;start<='0';

 when s7=> present_state<=s6;start<='0';

 when s6=> present_state<=s5;start<='0';

 when s5=> present_state<=s4;start<='0';

 when s4=> present_state<=s3;start<='0';

 when s3=> present_state<=s2;start<='0';

 when s2=> present_state<=s1;start<='0';

 when s1=> present_state<=s0;start<='1';

  when s0=> present_state<=present_state;

  when others=>null;start<='1';

  end case;

  end if;

  end if;

  end process p4;

 end body_daojishi;

  library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

 entity decode is

 port(clk_in:in std_logic;

 --1MHz

 record1,record2:in std_logic_vector(1 downto 0); --比分状态输入

 lights:in std_logic_vector(2 downto 0);

  --绳子状态输入

 led:out std_logic_vector(7 downto 0);

 --绳子解码后输出

 q:buffer std_logic_vector(5 downto 0);

 --数码管控制

 cats:out std_logic_vector(6 downto 0));

  --数码管显示

  end decode;

 architecture body_decode of decode is

 signal tmp_led:std_logic_vector(7 downto 0);

  --绳子输出

 signal tmp_da1:std_logic_vector(6 downto 0);

  --比分1

 signal tmp_da2:std_logic_vector(6 downto 0);

  --比分2

 signal tmp:std_logic_vector(6 downto 0);

 --比分显示

 begin

  led<=tmp_led;

  cats<=tmp;

  process(clk_in,lights,record1,record2,q,tmp_da2,tmp_da1,tmp)

  begin

 case lights is

  --绳子状态

  when “100“=> tmp_led<=“00010000“;

  when “011“=> tmp_led<=“00001000“;

  when “010“=> tmp_led<=“00000100“;

  when “001“=> tmp_led<=“00000010“;

  when “101“=> tmp_led<=“00100000“;

  when “110“=> tmp_led<=“01000000“;

  when “111“=> tmp_led<=“10000000“;

  when others =>tmp_led<=“00010000“;

 end case;

 case record1 is

  --比分状态

  when “00“=> tmp_da1<=“1111110“;

  when “01“=> tmp_da1<=“0110000“;

  when “10“=> tmp_da1<=“1101101“;

  when “11“=> tmp_da1<=“1111001“;

 end case;

 case record2 is

  --比分状态

  when “00“=> tmp_da2<=“1111110“;

  when “01“=> tmp_da2<=“0110000“;

  when “10“=> tmp_da2<=“1101101“;

  when “11“=> tmp_da2<=“1111001“;

 end case;

 if(clk_in='1') then

  q<=“111110“;

 end if;

 if(clk_in='0') then

  q<=“011111“;

 end if;

 case q is

 --数码管显示控制

  when “011111“=> tmp<=tmp_da2;

  when “111110“=> tmp<=tmp_da1;

  when others=> tmp<=“0000000“;

 end case;

  end process;

 end body_decode; 3、仿真及仿真结果分析 创建一个仿真波形文件,输入引脚,并对所有input引脚付出值,保存仿真波形文件。开始仿真,若仿真没有出错,则可观察仿真得到的波形图。仿真波形图如下:

 (1)当a输入的频率大于b时,可观察到led:低电平有规则的向左移动。即向a方向移动,符合设计要求。见仿真图1。

 (2)改变输入a b的大小,b的输入频率大于a,得到的波形如下,由波形图可知低电平向右边移动,即向b方向移动,符合设计要求。见仿真图2。

  仿真图1

 仿真图2 4、实验调试结果 编程下载及配置,选择Assignments

 —Assignments Editor ,在Assignments Edito窗口中选择pin标签页,按下图分配引脚。重编译,并进行编程下载到SOPC开发板进行功能验证。验证,按key 1和key10,观察led灯和数码管的显示变化是否符合设计要求,如果和设计不符合对程序进行更改,知道符合设计要求。

 三、结论及心得体会 EDA课程设计要求做一个拔河游戏机,电路使用9个发光二极管,开后只有中间一个发亮,此即拔河的中心点。游戏双方各持一个按钮,迅速地、不断地按动,产生脉冲,谁按得快,亮点就向谁的方向移动,每按十次,亮点移动一次。亮点移到任一方终端二极管时,这一方就获胜,此时双方按钮均无作用,输出保持,只有复位后才使亮点恢复到中心。用数码管显示双方按键的次数。

 通过这次课程设计,我更加感到理论和实际之间的差异很大。我也越来越强烈地感到要掌握一门技术,唯一的办法也是最好的办法就是实践。只有通过实践才能将书本上的知识应用,也只有实践才能发现很多问题,真正掌握知识,学以致用。虽然遇到的问题很多,但是同时得到很多有用的经验。这些对于以后的学习和工作都是很有用的。

  四、参考资料 [1] 潘

 松,EDA技术实用教程(第二版). 北京:科学出版社,2005. [2] 谭京生,EDA技术及应用[M],西安:西安电子科技大学出版社,2001 [3] 徐志军,CPLD/FPGA的开发与应用[M],北京:电子工业出版社,2001 [4] 朱正伟,EDA技术与应用[M],北京:清华大学出版社,2005 [5] 潘

 松,VHDL实用教程[M],成都:电子科技大学出版社,2001

 

Tags: 拔河   游戏机   课程设计  

搜索
网站分类
标签列表