乒乓球游戏机设计的问题,求关注

2019-03-25 09:51发布

各位大虾,我有一程序描述的是乒乓球游戏机,可是当球处于刚过网的时候,即i=4或5时,仿真击球会出现问题,还请大虾们能够解释下,多谢了。。 library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;     --引用必要的库函数和包集合
entity pingponggame is   --实体名为pingponggame
  port(reset:in std_logic;
       clk:in std_logic;
       startbutton:in std_logic;                        --开始游戏输入端口
       serve:in std_logic_vector(1 to 2);               --发球输入端口
       hit1,hit2:in std_logic;                          --甲和乙的击球输入端口
       light:out std_logic_vector(1 to 8);              --控制8个发光二极管的输出端口
       score11,score12,score21,score22:out std_logic_vector(1 to 7));         --4个用于控制4个7段译码器的输出端口
end pingponggame;
architecture game of pingponggame is
type pingpong is (waitserve,light1on,ballmoveto2,allow2hit,light8on,ballmoveto1,allow1hit);   ---设置7个状态,为枚举数据类型,记为pingpong
signal state:pingpong;
signal i:integer range 0 to 8;
signal count1,count2:std_logic_vector(1 to 5):="00000"; ---内部计数器,是5位二进制变量
component mydecoder is
port(binaryin: in std_logic_vector(1 to 5);
bcdout1:out std_logic_vector(1 to 7);
bcdout2:out std_logic_vector(1 to 7));
end component;                                          ---调用记分译码器
begin
process(clk)                                            --状态机进程
  begin
    if reset='1' then    --异步置位
      i<=0;
      count1<="00000";
      count2<="00000";
    elsif clk'event and clk='1' then  --当处于时钟inclock上升沿时  
      if count1="10101"or count2="10101"then
        i<=0;
        count1<="00000";
        count2<="00000";
      elsif startbutton='0' then
        i<=0;
        count1<="00000";
        count2<="00000";
      else        --以下case语句是程序中最关键的状态机部分
        case state is
          when waitserve=>   --进程处于等待发球状态
            case serve is
              when "10"=> i<=1;state<=light1on;
              when "01"=> i<=8;state<=light8on;
              when others=> i<=0;
            end case;
          when light1on=>     --进程处于第一盏灯亮状态
            i<=2;
            if hit2='1' then
              i<=0;
              count1<=count1+1;state<=waitserve;  
            else
              state<=ballmoveto2;
            end if;
          when light8on=>     --进程处于第八盏灯亮状态
            i<=7;
            if hit1='1' then
              i<=0;
              count2<=count2+1;state<=waitserve;
            else
              state<=ballmoveto1;
            end if;
          when ballmoveto1=>       --进程处于球向甲移动状态
            if hit1='1' then
              i<=0;
              count2<=count2+1;
              state<=waitserve;
            elsif i=5 then
              i<=4;
              state<=allow1hit;
            else i<=i-1;
            end if;
          when ballmoveto2=>      --进程处于球向乙移动状态
            if hit2='1'then
              i<=0;
              count1<=count1+1;state<=waitserve;
            elsif i=4 then
              i<=5;
              state<=allow2hit;
            else
              i<=i+1;
            end if;
          when allow1hit=>       --进程处于允许甲击球状态
              if hit1='1' then
                i<=i+1;
                state<=ballmoveto2;
              elsif i=1 then
                count2<=count2+1;
                i<=0;
                state<=waitserve;
               else 
                i<=i-1;
              end if;
          when allow2hit=>      --进程处于允许乙击球状态
              if hit2='1'then
                i<=i-1;
                state<=ballmoveto1;
              elsif i=8 then
                count1<=count1+1;
                i<=0;
                state<=waitserve;
              else  
                i<=i+1;
            end if;
        end case;
      end if;
    end if;
end process;
light<="10000000"when(i=1) else                --进程处i信号控制发光二极管的亮暗
"01000000" when(i=2) else
"00100000" when(i=3) else
"00010000" when(i=4) else
"00001000" when(i=5) else
"00000100" when(i=6) else
"00000010" when(i=7) else
"00000001" when(i=8) else
"00000000";                                    --其他情况所有发光二极管都暗
u0:mydecoder port map(count1,score11,score12); --用七段译码器显示甲的分数
u1:mydecoder port map(count2,score21,score22); --用七段译码器显示乙的分数
end game;
以下程序是调用的mydecoder程序,说明的是用七段数码管显示分数。。   library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mydecoder is
port(binaryin:in std_logic_vector(1 to 5);    --5位二进制码的输入端口
bcdout1:out std_logic_vector(1 to 7);         --七段译码器输出端口
bcdout2:out std_logic_vector(1 to 7));
end mydecoder;
architecture m of mydecoder is
signal tembinaryin:std_logic_vector(1 to 5);
begin
process(binaryin)
  begin
    tembinaryin<=binaryin;
    case tembinaryin is                      
      when"00000"=>bcdout1<="1111110";bcdout2<="1111110";  --把0到9的5位二进制码转换成七段译码
      when"00001"=>bcdout1<="1111110";bcdout2<="0110000";
      when"00010"=>bcdout1<="1111110";bcdout2<="1101101";
      when"00011"=>bcdout1<="1111110";bcdout2<="1111001";
      when"00100"=>bcdout1<="1111110";bcdout2<="0110011";
      when"00101"=>bcdout1<="1111110";bcdout2<="1011011";
      when"00110"=>bcdout1<="1111110";bcdout2<="1011111";
      when"00111"=>bcdout1<="1111110";bcdout2<="1110000";
      when"01000"=>bcdout1<="1111110";bcdout2<="1111111";
      when"01001"=>bcdout1<="1111110";bcdout2<="1111011";
      when"01010"=>bcdout1<="0110000";bcdout2<="1111110";--把10到19的5位二进制码转换成七段译码
      when"01011"=>bcdout1<="0110000";bcdout2<="0110000";
      when"01100"=>bcdout1<="0110000";bcdout2<="1101101";
      when"01101"=>bcdout1<="0110000";bcdout2<="1111001";
      when"01110"=>bcdout1<="0110000";bcdout2<="0110011";
      when"01111"=>bcdout1<="0110000";bcdout2<="1011011";
      when"10000"=>bcdout1<="0110000";bcdout2<="1011111";
      when"10001"=>bcdout1<="0110000";bcdout2<="1110000";
      when"10010"=>bcdout1<="0110000";bcdout2<="1111111"
      when"10011"=>bcdout1<="0110000";bcdout2<="1111011";
      when"10100"=>bcdout1<="1101101";bcdout2<="1111110";--把20到21的5位二进制码转换成七段译码
      when"10101"=>bcdout1<="1101101";bcdout2<="0110000";
      when others=>bcdout1<="1101101";bcdout2<="1111110";--如果5位二进制码不在0到21范围内,那么两个七段译码器都显示0
    end case;
end process;
end m;
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
eeleader
1楼-- · 2019-03-25 14:11
< /

会出现啥问题?能具体描述吗

jjkwz
2楼-- · 2019-03-25 16:39
各位大虾,我有一程序描述的是乒乓球游戏机,可是当球处于刚过网的时候,即i=4或5时,仿真击球会出现问题,还请大虾们能够解释下,多谢了。。
你的仿真击球会出现什么问题,程序出错没,会不会是时序没有对准呢
eeleader
3楼-- · 2019-03-25 22:37
 精彩回答 2  元偷偷看……

一周热门 更多>