EDA拔河游戏机课程设计.docx
- 文档编号:11663119
- 上传时间:2023-03-29
- 格式:DOCX
- 页数:18
- 大小:20.10KB
EDA拔河游戏机课程设计.docx
《EDA拔河游戏机课程设计.docx》由会员分享,可在线阅读,更多相关《EDA拔河游戏机课程设计.docx(18页珍藏版)》请在冰豆网上搜索。
EDA拔河游戏机课程设计
EDA拔河游戏机课程设计
*****院课程设计
题
目:
EDA拔河游戏机课程设计
作
者:
XXX
专
业:
自动化
班
级:
XXX
学
号:
XXXXX
指导老师:
XXX
20XX年X月X日主要内容、基本要求、主要参考资料等主要内容:
电子拔河游戏机是一种能容纳甲乙双方参赛游戏电路。
由一排发光二极管表示拔河的“电子绳”。
由甲乙双方通过按纽开关使发光二极管向一方的终点延伸,当延伸到某方的最后一个发光二极管时,则该方获胜,连续比赛多局以定胜负。
基本要求:
1、设计一个能进行拔河游戏的电路。
2、电路使用9个发光二极管,开机后只有中间一个发亮,此即拔河的中心点。
3、游戏双方各持一个按钮,迅速地、不断地按动,产生脉冲,谁按得快,亮点就向谁的方向移动,每按一次,亮点移动一次。
4、亮点移到任一方终端二极管时,这一方就获胜,此时双方按钮均无作用,输出保持,只有复位后才使亮点恢复到中心。
5、用数码管显示获胜者的盘数。
主要参考资料:
潘松著.EDA技术实用教程(第二版).北京:
科学出版社,20XX年.康华光主编.电子技术基础模拟部分.北京:
高教出版社,20XX年.阎石主编.数字电子技术基础.北京:
高教出版社,20XX年.
一、总体设计思想1.基本原理由设计内容可知,需要一个十进制的计数器,用于对双方按钮的次数计数,并通过译码器显示在数码管上。
设计要求用50MHz的频率,而设计用到的是1KHz的频率,所以要设计一个程序进行分频。
显视控制部分设计要求在发光二极管上显示游戏状态,双方每按十次,亮点向先按十次移动一次,对脉冲进行计数,每十次移一位。
需接入一个清零端,用于复位。
将以上程序组装起来。
2.设计框图译码器编码电路
选择开关整形电路可逆计数器控制电路
图1.拔河机游戏机框图
二、设计步骤和调试过程1、总体设计电路总体电路图和仿真图如图(25)所示,由仿真图可知,此电路设计无误,可以实现按动A、B两个按键时,分别产生两个脉冲信号,经整形后分别加到可逆计数器上,可逆计数器输出的代码经译码器译码后驱动电平指示灯点亮并产生位移,当亮点移到任何一方终端后,由于控制电路的作用,使这一状态被锁定,双方按键产生的输入脉冲不起作用。
如按动复位键C,亮点又回到中点位置,再次按C键则比赛又可重新开始。
图2.电路图2、模块设计和相应模块程序1.顶层文件libraryIEEE;useIEEE.std_logic_1164.all;useIEEE.std_logic_unsigned.all;
entitybaheis
port(
player1,player2:
instd_logic;--玩家1,2输入
clk_in:
instd_logic;
--clk_in(1MHZ)
reset:
instd_logic;
--重置键
row:
outstd_logic_vector(7downto0);
col:
outstd_logic_vector(7downto0);
led:
outstd_logic_vector(7downto0);--绳子
cats:
outstd_logic_vector(6downto0);--比分
q:
outstd_logic_vector(5downto0);
--数码管控制
mus:
outstd_logic);
--蜂鸣输出endbahe;
architecturebody_baheofbaheis--分频模块
componentdivision
port(
clk_in:
instd_logic;
--1MHZ输入
clk_100,clk_5,clk_1:
outstd_logic);--100HZ,5Hz,1HZ
endcomponent;--计数模块
componentcount
port(
clk_1:
instd_logic;
--1HZ输入
sw:
instd_logic;
--状态开关
player1,player2:
instd_logic;--选手输入
sum1,sum2:
outstd_logic_vector(4downto0));--计数结果输出
endcomponent;--比较模块
componentcmp
port(
clk_100:
instd_logic;--100hz
clk_1:
instd_logic;
--1hz
sw:
outstd_logic;
--状态开关输出
reset:
instd_logic;
--重置
start:
instd_logic;
--开始
sum1,sum2:
instd_logic_vector(4downto0);--计数结果输入
music_begin:
outstd_logic;
--音乐
record1,record2:
outstd_logic_vector(1downto0);--比分输出
lights:
outstd_logic_vector(2downto0));
--拔河绳子显示
endcomponent;--音乐模块
componentmusic
port(
reset:
instd_logic;
--重置
clk:
instd_logic;
--1MHz
clk_5:
instd_logic;
--5hz
music_begin:
instd_logic;
--音乐开始
mus:
outstd_logic);
endcomponent;--译码模块
componentdecode
port(
clk_in:
instd_logic;
--1mHZ
record1,record2:
instd_logic_vector(1downto0);--比分输入
lights:
instd_logic_vector(2downto0);--拔河绳子输入
led:
outstd_logic_vector(7downto0);--输出到LED
q:
bufferstd_logic_vector(5downto0);
--数码管控制
cats:
outstd_logic_vector(6downto0)--数码管显示比分
);
endcomponent;--倒计时模块
componentdaojishi
port(
clk_in,clk_1,reset:
instd_logic;
row:
outstd_logic_vector(7downto0);
col:
outstd_logic_vector(7downto0);
start:
outstd_logic
);
endcomponent;
--分频器输出
signalclk_100,clk_5,clk_1:
std_logic;--时钟信号
--计数器输出
signalsum1,sum2:
std_logic_vector(4downto0);
--计数结果
--比较器输出
signalsw:
std_logic;
--状态开关
signalrecord1,record2:
std_logic_vector(1downto0);--比分
signallights:
std_logic_vector(2downto0);
--绳子
signalmusic_begin:
std_logic;
--解码器输出
signaltmp_led:
std_logic_vector(7downto0);--LED显示
signaltmp_q:
std_logic_vector(5downto0);
--数码管控制
signal
tmp_cat:
std_logic_vector(6downto0);--数码管显示比分
--倒计时器输出
signaltmp_start:
std_logic;
begin
cats=tmp_cat;
q=tmp_q;
led=tmp_led;
div:
divisionportmap(clk_in=clk_in,clk_100=clk_100,clk_5=clk_5,clk_1=clk_1);
cnt:
countportmap(
clk_1=clk_1,sw=sw,player1=player1,player2=player2,
sum1=sum1,sum2=sum2);
com:
cmpportmap(
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:
decodeportmap(
clk_in=clk_in,record1=record1,record2=record2,
lights=lights,led=tmp_led,q=tmp_q,cats=tmp_cat);
mu:
musicportmap(
reset=reset,clk=clk_in,clk_5=clk_5,
music_begin=music_begin,mus=mus);
dao:
daojishiportmap(
clk_in=clk_in,clk_1=clk_1,reset=reset,
start=tmp_start,col=col,row=row);
endbody_bahe;2.CMP模块
libraryIEEE;useIEEE.std_logic_1164.all;useIEEE.std_logic_unsigned.all;
entitycmpis
port(clk_100:
instd_logic;
--100HZ输入
clk_1:
instd_logic;
--1HZ输入
reset:
instd_logic;
--重置
start:
instd_logic;
--开始
sum1,sum2:
instd_logic_vector(4downto0);
--计数输入
record1,record2:
outstd_logic_vector(1downto0);--比分输出
music_begin:
outstd_logic;
--音乐开始
sw:
outstd_logic;
--状态输出
lights:
outstd_logic_vector(2downto0));
--绳子状态
endcmp;
architecturebody_cmpofcmpis
signaltmp_record1:
std_logic_vector(1downto0);
--比分
signaltmp_record2:
std_logic_vector(1downto0);
signaltmp:
std_logic_vector(2downto0);
--绳子状态
signaltmp_sta:
std_logic;
--状态
signals1,s2:
std_logic_vector(4downto0);
--计数
begin
record1=tmp_record1;
record2=tmp_record2;
lights=tmp;
sw=tmp_sta;
process(clk_100)
--判断比赛状态
begin
if(start='1')then
if(clk_100'eventandclk_100='1')then
tmp_sta='1';
endif;
endif;
if(clk_100'eventandclk_100='1')then
--任意比分到3,比赛结束,开始播放音乐
if(tmp_record1=“11“ortmp_record2=“11“)then
tmp_sta='0';
music_begin='1';
endif;
if(tmp=“001“ortmp=“111“)then
--绳子到头,进入等待状态
tmp_sta='0';
endif;
if(reset='1')then
--复位,状态归零
tmp_sta='0';
music_begin='0';
endif;
endif;
endprocess;
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'eventandclk_1='1')then
if(tmp_sta='1')then
if(s1s2)thentmp=tmp-'1';
--绳子左移
elsif(s1=s2)thentmp=tmp;
--绳子保持原状
elsetmp=tmp+'1';
--绳子右移
endif;
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“;
endif;
endif;
endif;
endif;
endprocess;
endbody_cmp;3.COUT模块
useIEEE.std_logic_1164.all;useIEEE.std_logic_unsigned.all;
entitycountis
libraryIEEE;port(clk_1:
instd_logic;
--1HZ输入
sw:
instd_logic;
--状态判断输入
player1,player2:
instd_logic;
--选手输入
sum1,sum2:
outstd_logic_vector(4downto0));--计数输出
endcount;
architecturebody_countofcountis
signalp1,p2:
std_logic_vector(4downto0);
--计数输出
begin
sum1
sum2
process(player1,player2,sw,clk_1)
begin
if(sw='1')then
--处于比赛状态
if(clk_1='0')then
if(player1'eventandplayer1='1')then
p1=p1+'1';
endif;
if(player2'eventandplayer2='1')then
p2=p2+'1';
endif;
else
p1=“00000“;
p2=“00000“;
endif;
--比赛状态结束
elsep1=“00000“;
p2=“00000“;
endif;
endprocess;
endbody_count;4.daojishi模块
libraryIEEE;useIEEE.std_logic_1164.all;useIEEE.std_logic_unsigned.all;
entitydaojishiis
port(clk_1,clk_in,reset:
instd_logic;
row:
outstd_logic_vector(7downto0);
col:
outstd_logic_vector(7downto0);
start:
outstd_logic);enddaojishi;
architecturebody_daojishiofdaojishiis
typestateis(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
signalpresent_state:
state:
=s10;
signalnum:
std_logic_vector(2downto0):
=“000“;
begin
p3:
process(clk_in)
begin
ifclk_in'eventandclk_in='1'then
ifnum=“101“thennum=“000“;
elsenum=num+1;
casepresent_stateis
whens9=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens8=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens7=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens6=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens5=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens4=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens3=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001“=col=“***-*****“;row=“***-*****“;
when“010“=col=“***-*****“;row=“***-*****“;
when“011“=col=“***-*****“;row=“***-*****“;
when“100“=col=“***-*****“;row=“***-*****“;
whenothers=col=“***-*****“;row=“***-*****“;
endcase;
whens2=
casenumis
when“000“=col=“***-*****“;row=“***-*****“;
when“001
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- EDA 拔河 游戏机 课程设计
