设计一拔河游戏机
1、设计一个能进行拔河游戏的电路。
2、电路使用11个发光二极管,开机后只有中间一个发亮,此即拔河的中心点。游戏双方各持一个按钮(本次游戏使用KEY1和KEY2),迅速地、不断地按动,产生脉冲,谁按得快,亮点就向谁的方向移动,每按一次,亮点移动一次。
3、亮点移到任一方终端二极管时,这一方就获胜,此时双方按钮均无作用,输出保持,只有复位后才使亮点恢复到中心。
4、用两个数码管显示玩家按的次数。结束一局后用KEY3可以清除双方按的次数。
4、用两个数码管显示获胜者的盘数。游戏结束后可以用KEY4清除双方的比分
大家一起来玩这个游戏吧!
视频:
整体电路图:
玩家按键模块:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH;
entity baheji IS
PORT (
reset,key1,key2 : in std_logic;
led6: out std_logic;
count1,count2: out std_logic_vector(3 downto 0)
);
end baheji;
architecture behave of baheji is
signal count1_r: std_logic_vector(3 downto 0);
signal count2_r: std_logic_vector(3 downto 0);
begin
u1:process(key1,reset)
begin
if reset='0'then
led6<='0'; count1_r<="0000";
else
if key1'event and key1='0'then
count1_r(3 downto 0)<=count1_r(3 downto 0)+1;
end if;
end if;
end process;
count1<=count1_r;
u2:process(key2,reset)
begin
if reset='0' then
count2_r<="0000";
else
if key2'event and key2='0'then
count2_r(3 downto 0)<=count2_r(3 downto 0)+1;
end if;
end if ;
end process;
count2<=count2_r;
end behave;
一方玩家按键次数计数模块:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH;
entity bijiao IS
PORT (
clk:in std_logic;
count1 : in std_logic_vector(3 downto 0);
count2 : in std_logic_vector(3 downto 0);
led1,led2,led3,led4,led5,led6:out std_logic
);
end bijiao;
architecture behave of bijiao is
signal kongzhi1: std_logic_vector(3 downto 0);
begin
kongzhi1<=count1-count2;
process(kongzhi1)
begin
if clk'event and clk='1' then
case(kongzhi1)is
when "0000"=>led6<='0';led5<='1';led4<='1';led3<='1';led2<='1';led1<='1';
when "0001"=>led5<='0';led6<='1';led4<='1';led3<='1';led2<='1';led1<='1';
when "0010"=>led4<='0';led6<='1';led5<='1';led3<='1';led2<='1';led1<='1';
when "0011"=>led3<='0';led6<='1';led5<='1';led4<='1';led2<='1';led1<='1';
when "0100"=>led2<='0';led6<='1';led5<='1';led4<='1';led3<='1';led1<='1';
when "0101"=>led1<='0';led6<='1';led5<='1';led4<='1';led3<='1';led2<='1';
when others=>led6<='1';led5<='1';led4<='1';led3<='1';led2<='1';led1<='1';
-- when others=> null;
end case;
end if;
end process;
end behave;
另一方方玩家按键次数计数模块:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH;
entity bijiao2 IS
PORT (
clk:in std_logic;
count1 : in std_logic_vector(3 downto 0);
count2 : in std_logic_vector(3 downto 0);
led6,led7,led8,led9,led10,led11:out std_logic
);
end bijiao2;
architecture behave of bijiao2 is
signal kongzhi: std_logic_vector(3 downto 0);
-- signal led11_r: std_logic;
begin
kongzhi<=count2-count1;
process(kongzhi)
begin
if clk'event and clk='1' then
--if led11_r<='0' then
-- led6<='1'; led7<='1';
-- led8<='1';led10<='1';
-- led10<='1';
case(kongzhi)is
when "0000"=>led6<='0';led7<='1'; led8<='1';led9<='1';led10<='1';led11<='1';
when "0001"=>led7<='0';led6<='1'; led8<='1';led9<='1';led10<='1';led11<='1';
when "0010"=>led8<='0';led6<='1'; led7<='1';led9<='1';led10<='1';led11<='1';
when "0011"=>led9<='0';led6<='1'; led7<='1';led8<='1';led10<='1';led11<='1';
when "0100"=>led10<='0';led6<='1'; led7<='1';led8<='1';led9<='1';led11<='1';
when "0101"=>led11<='0';led6<='1'; led7<='1';led8<='1';led10<='1';led10<='1';
when others=>led11<='1';led6<='1'; led7<='1';led8<='1';led10<='1';led10<='1';
--when others=> null;
end case;
end if;
-- end if;
--led11<=led11_r;
end process;
end behave;
计入一家玩家所赢的盘数模块:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH;
entity jishu IS
PORT (led1: in std_logic;
bifen1 : out std_logic_vector(3 downto 0);
reset : in std_logic
);
end jishu;
architecture behave of jishu is
signal bifen1_r: std_logic_vector(3 downto 0);
begin
process(led1,reset)
begin
if reset='0'then
bifen1_r<="0000";
else
if led1'event and led1='0'then
bifen1_r(3 downto 0)<=bifen1_r(3 downto 0)+1;
end if;
end if;
end process;
bifen1<=bifen1_r;
end behave;
计入另一家玩家所赢的盘数模块:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH;
entity jishu2 IS
PORT (led11: in std_logic;
bifen2 : out std_logic_vector(3 downto 0);
reset : in std_logic);
end jishu2;
architecture behave of jishu2 is
signal bifen2_r: std_logic_vector(3 downto 0);
begin
u2:process(led11,reset)
begin
if reset='0'then
bifen2_r<="0000";
else
if led11'event and led11='0'then
bifen2_r(3 downto 0)<=bifen2_r(3 downto 0)+1;
end if;
end if;
end process;
bifen2<=bifen2_r;
end behave;
其他的都是我们经常用到的,数码管驱动模块、分频模块和消抖模块,一起经常公布这里就不公布了。
拔河机.SOF文件下载地址。Y2晶振:http://share.eepw.com.cn/share/download/id/82903
大家可以下载区玩玩!