乒乓球游戏电路设计.doc
文本预览下载声明
1、主要内容:
设计一个乒乓球游戏机,能模拟比赛的基本过程和规则并能自动裁判和记分基本要求:1、设计一个由甲、乙双方参赛,有裁判的3人乒乓球游戏机。
2、用8个(或更多个)LED排成一条直线,以中点为界,两边各代表参赛双方的位置,其中一只点亮的LED指示球的当前位置,点亮的LED依此从左到右,或从右到左,其移动的速度应能调节。
3、当“球”(点亮的那只LED)运动到某方的最后一位时,参赛者应能果断地按下位于自己一方的按钮开关,即表示启动球拍击球。若击中,则球向相反方向移动;若未击中,则对方得1分。一方得分时,电路自动响铃3秒,这期间发球无效,等铃声停止后方能继续比赛。
、设置自动记分电路,甲、乙双方各用2位数码管进行记分显示,每计满21分为1局。
、甲、乙双方各设一个发光二极管,表示拥有发球权,每隔5次自动交换发球权,拥有发球权的一方发球才有效。主要参考资料:
[1] 潘松著.EDA技术实用教程(第二版). 北京:科学出版社,2005[2] 康华光主编电子技术基础 模拟部分 北京:高教出版社[3] 阎石主编数字电子技术基础 北京:高教出版社用8个(或更多个)LED排成一条直线,以中点为界,两边各代表参赛双方的位置,其中一只点亮的LED指示球的当前位置,点亮的LED依此从左到右,或从右到左,其移动的速度应能调节当“球”(点亮的那只LED)运动到某方的最后一位时,参赛者应能果断地按下位于自己一方的按钮开关,即表示启动球拍击球。若击中,则球向相反方向移动;若未击中,则对方得1分。一方得分时,电路自动响铃3秒,这期间发球无效,等铃声停止后方能继续比赛。设置自动记分电路,甲、乙双方各用2位数码管进行记分显示,每计满21分为1局。甲、乙双方各设一个发光二极管,表示拥有发球权,每隔5次自动交换发球权,拥有发球权的一方发球才有效。
1.2乒乓游戏机的电路框图
2、模块设计和相应模块程序
系统各功能模块的实现
1、 模块SEL的实现
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sel is
port(clk:in std_logic;
sell:out std_logic_vector(2 downto 0));
end sel;
architecture sel_arc of sel is
begin
process(clk)
variable tmp:std_logic_vector(2 downto 0);
begin
if(clkevent and clk=1)then
if(tmp=000)then
tmp:=001;
elsif tmp=001then
tmp:=100;
elsif tmp=100then
tmp:=101;
elsif tmp=101then
tmp:=000;
end if;
end if;sell=tmp;
end process;
end sel_arc;
2、模块CORNA的实现
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity coma is
port(clr,af,aj,bf,bj,clk:in std_logic;
shift:out std_logic_vector(7 downto 0);
ah,al,bh,bl:out std_logic_vector(3 downto 0));
end coma;
architecture com_arc of coma is
signal amark,bmark:integer;
begin
process(clr,clk)
variable a,b:std_logic;
variable she:std_logic_vector(7 downto 0);
begin
if clr=0then
a:=0;
b:=0;
she:
amark=0;
bmark=0;
elsif clkevent and clk=1then
if a=0 and b=0 and af=0then
a:=1;
she:
elsif a=0 and b=0 and bf=0 then
b:=1;
she:
elsif a=1and b=0then
if she8 then
if bj=0then
amark=am
显示全部