⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ball.vhd

📁 清华大学实验箱自带实验程序
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ball is
    Port ( clk : in std_logic;
			  hcnt : in std_logic_vector(10 downto 0);
			  vcnt : in std_logic_vector(9 downto 0);
           reset : in std_logic;
			  hit_target : in std_logic;
           --xsign : in std_logic;
           board_loc : in std_logic_vector(9 downto 0);
           --ball_loc : out std_logic_vector(9 downto 0);
			  ballx : out std_logic_vector(9 downto 0);
			  bally : out std_logic_vector(9 downto 0);
           ballrgb : out std_logic_vector(7 downto 0));
end ball;

architecture Behavioral of ball is

signal movclk : std_logic;
signal hcount : std_logic_vector(10 downto 0);
signal vcount : std_logic_vector(9 downto 0);
signal ball_x,ball_y : std_logic_vector(9 downto 0);
signal move_x,move_y : std_logic_vector(9 downto 0);
signal lose : std_logic;--when '1' the ball is losen

begin

movclk <= vcount(6);
hcount <= hcnt;
vcount <= vcnt;

ballx <= ball_x;
bally <= ball_y;

drawball: process (clk)
begin
  if (clk'event and clk='1') then
    if ((hcount>=(ball_x-2)) and (hcount<=(ball_x+2)) and (vcount>=(ball_y-2)) and (vcount<=(ball_y+2))) or
	   ((hcount>=(ball_x-1)) and (hcount<=(ball_x+1)) and (vcount>=(ball_y-3)) and (vcount<=(ball_y+3))) or
		((hcount>=(ball_x-3)) and (hcount<=(ball_x+3)) and (vcount>=(ball_y-1)) and (vcount<=(ball_y+1))) then
		ballrgb <= "11000111";
	 else
	   ballrgb <= "00000000";
	 end if;
  end if;
end process;

ballmove: process (movclk,reset)
begin
  if reset='1' then
    ball_x <= "0110010000";
	 ball_y <= "0100101100";
  elsif (movclk'event and movclk='1') then
    if (lose='1' or hit_target='1') then
	   ball_x <= "0110010000";
	   ball_y <= "0100101100";
	 else
      ball_x <=ball_x + move_x;
	   ball_y <=ball_y + move_y;
	 end if;
  end if;
end process;

movablex: process (movclk,reset)
begin
  if reset='1' then
    move_x <= "0000000001";
  elsif (movclk'event and movclk='1') then
    if (ball_x=23) then
	   move_x <= "0000000001";
	 elsif (ball_x=776) then
	   move_x <= "1111111111";
	 end if;
  end if;
end process;

movabley: process (movclk,reset)
begin
  if reset='1' then
    move_y <= "0000000001";
	 lose <= '0';
  elsif (movclk'event and movclk='1') then
    if (ball_y=23) then
	   move_y <= "0000000001";
	 elsif (ball_y=566) then
	   if (board_loc>=(ball_x-19)) and (board_loc<=(ball_x+19)) then
	     move_y <= "1111111111";
		  lose <= '0';
		else
		  lose <= '1';
		end if;
	 else 
	   lose <= '0';
	 end if;
  end if;
end process;

end Behavioral;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -