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

📄 vgacore.vhd

📁 这是非常好的vhdl例子
💻 VHD
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity vgacore is
	port
	(
		reset : in std_logic;	-- reset
		clock : in std_logic;	-- VGA dot clock
		hsyncb : buffer std_logic;	-- horizontal (line) sync
		vsyncb : buffer std_logic;	-- vertical (frame) sync
      model : in std_logic_vector(2 downto 0); --background color select.
		rgb : buffer std_logic_vector(2 downto 0);-- red,green,blue colors
		read_data : in std_logic; -----the flag show data is ready to be read
		lbutton : in std_logic;
		rbutton : in std_logic;
		mousex : in std_logic_vector(9 downto 0);
		mousey : in std_logic_vector(9 downto 0)  ------mouse data
);
end vgacore;

architecture vgacore_arch of vgacore is
signal hcnt: std_logic_vector(10 downto 0);	-- horizontal pixel counter
signal vcnt: std_logic_vector(9 downto 0);	-- vertical line counter
--signal pixrg: std_logic_vector(2 downto 0);	-- byte-wide register for 4 pixels
--signal blank: std_logic;					-- video blanking signal
signal pblank: std_logic;					-- pipelined video blanking signal
--signal div_clk: std_logic_vector(4 downto 0);
--signal hrgb: std_logic_vector(2 downto 0); -- red,green,blue h colors
signal vrgb,hrgb,frame: std_logic_vector(2 downto 0);-- red,green,blue v colors
signal mousehcnt: std_logic_vector(9 downto 0);	-- horizontal pixel counter
signal mousevcnt: std_logic_vector(9 downto 0);	-- vertical line counter
signal bangcolor: std_logic_vector(2 downto 0);
--signal bang: std_logic;
--signal mouse_clk: std_logic;
--signal flash_clk: std_logic;

begin

A: process(clock,reset)
begin
	-- reset asynchronously clears pixel counter
	if reset='0' then
		hcnt <= "00000000000";
	-- horiz. pixel counter increments on rising edge of dot clock
	elsif (clock'event and clock='1') then
		-- horiz. pixel counter rolls-over after 381 pixels
		if hcnt<1040 then
			hcnt <= hcnt + 1;
		else
			hcnt <= "00000000000";
		end if;
	end if;
end process;

B: process(hsyncb,reset)
begin
	-- reset asynchronously clears line counter
	if reset='0' then
		vcnt <= "0000000000";
	-- vert. line counter increments after every horiz. line
	elsif (hsyncb'event and hsyncb='1') then
		-- vert. line counter rolls-over after 528 lines
		if vcnt<666 then
			vcnt <= vcnt + 1;
		else
			vcnt <= "0000000000";
		end if;
	end if;
end process;

C: process(clock,reset)
begin
	-- reset asynchronously sets horizontal sync to inactive
	if reset='0' then
		hsyncb <= '1';
	-- horizontal sync is recomputed on the rising edge of every dot clock
	elsif (clock'event and clock='1') then
		-- horiz. sync is low in this interval to signal start of a new line
		if (hcnt>=856 and hcnt<=976) then -- and hcnt<=800) then
			hsyncb <= '1';
		else
			hsyncb <= '0';
		end if;
	end if;
end process;

D: process(hsyncb,reset)
begin
	-- reset asynchronously sets vertical sync to inactive
	if reset='0' then
		vsyncb <= '1';
	-- vertical sync is recomputed at the end of every line of pixels
	elsif (hsyncb'event and hsyncb='1') then
		-- vert. sync is low in this interval to signal start of a new frame
		if (vcnt>=637 and vcnt<=643) then
			vsyncb <= '1';
		else
			vsyncb <= '0';
		end if;
	end if;
end process;

--E: blank <= '1' when ((hcnt<=16 and hcnt>=640) or (vcnt<=5 and vcnt>=480)) else '0';
--E: blank <= (hsyncb or vsyncb);

F: process(clock,reset)
begin
	if reset='0' then
		pblank <= '0';
	elsif (clock'event and clock='1') then
	  if (hcnt>799 or vcnt>599) then
	    pblank<='1';
	  else
		 pblank <= '0';
	  end if;
	end if;
end process;

K: process(pblank,clock,hcnt,vcnt)
begin
 if (clock'event and clock='1') then
    if pblank='0' then
			case hcnt(7 downto 5) is
				when "000" =>   hrgb <= "100";	-- red
				when "001" =>   hrgb <= "010";	-- green
				when "010" =>   hrgb <= "001";	-- blue
				when "011" =>   hrgb <= "110";	-- red
				when "100" =>   hrgb <= "011";	-- red
				when "101" =>   hrgb <= "101";	-- green
				when "110" =>   hrgb <= "000";	-- blue
				when "111" =>   hrgb <= "111";	-- red
				when others =>   hrgb <= "000";	-- white
			end case;
			case vcnt(7 downto 5) is
				when "000" =>   vrgb <= "100";	-- red
				when "001" =>   vrgb <= "010";	-- green
				when "010" =>   vrgb <= "001";	-- blue
				when "011" =>   vrgb <= "110";	-- red
				when "100" =>   vrgb <= "011";	-- red
				when "101" =>   vrgb <= "101";	-- green
				when "110" =>   vrgb <= "000";	-- blue
				when "111" =>   vrgb <= "111";	-- red
				when others =>   vrgb <= "000";	-- white
			end case;
		else
		   vrgb <= "000";
			hrgb <= "000";
		end if;
 end if;
end process;

XX: process(pblank,clock,hcnt,vcnt)
begin
 if (clock'event and clock='1') then
    if pblank='0' then
		if ((hcnt>=0 and hcnt<=9) or (hcnt>=790 and hcnt<=799) or
	       (vcnt>=0 and vcnt<=9) or (vcnt>=590 and vcnt<=599)) then
	 	  frame <= "100";
		else
		   frame <= "000";
		end if;
	 end if;
 end if;
end process;

L: process(model,clock)
begin
  if (clock'event and clock='1') then
   if ((hcnt>=(mousehcnt-12))and(hcnt<=mousehcnt+12)and(vcnt>=mousevcnt-2)and(vcnt<=mousevcnt+2)) or 
	      ((vcnt>=(mousevcnt-12))and(vcnt<=mousevcnt+12)and(hcnt>=mousehcnt-2)and(hcnt<=mousehcnt+2)) then
	  rgb <= "111" xor bangcolor;
	else
	  case model(2 downto 0) is
				when "000" =>   rgb <= "100" xor frame;	-- red
				when "001" =>   rgb <= "010" xor frame;	-- green
				when "010" =>   rgb <= "001" xor frame; --blue
 				when "011" =>   rgb <= (hrgb or vrgb) xor frame; --yellow
				when "100" =>   rgb <= (hrgb and vrgb) xor frame; 	-- teal
				when "101" =>   rgb <= (hrgb xor vrgb) xor frame; --grid
				when "110" =>   rgb <= hrgb xor frame; --h bar
 				when "111" =>   rgb <= vrgb xor frame; --v bar
				when others =>  rgb <="000"; 
     end case;
	end if;
  end if;
 end process;


MM: process(clock,reset)  -- press flash button then background color flashing.
begin
    if (clock'event and clock='1') then
    if reset='0' then
 		 mousehcnt <= "0110010000";  -- 400
		 mousevcnt <= "0100101100";  -- 300
	 else
	    mousehcnt <= mousex;
		 mousevcnt <= mousey;
	 end if;
	end if;
end process;

P: process(clock,reset) -- chang ball color;
begin
  if (reset='0') then
	 bangcolor <= "000";
  elsif (clock'event and clock='1') then
      --if (read_data='1') then
		  bangcolor <= lbutton & rbutton & '1';
		--else
        --bangcolor <= "000";
		--end if;
  end if;
end process;

end vgacore_arch;

⌨️ 快捷键说明

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