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

📄 vga_16.vhd

📁 含有各类寄存器
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

--  Uncomment the following lines to use the declarations that are
--  provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity vga_16 is
    Port ( clk : in std_logic;
           hs : out std_logic;
           vs : out std_logic;
           r : out std_logic;
           g : out std_logic;
           b : out std_logic;
		 	  innum  : in std_logic_vector(15 downto 0);
		     innum0 : in std_logic_vector(15 downto 0); 
           innum1 : in std_logic_vector(6 downto 0);
           innum2 : in std_logic_vector(6 downto 0);
           innum3 : in std_logic_vector(6 downto 0);
		     innum4 : in std_logic_vector(6 downto 0));
end vga_16;

architecture Behavioral of vga_16 is

constant  color1: std_logic_vector:="010";		--显示颜色为红色
constant  color2: std_logic_vector:="100";
constant  color3: std_logic_vector:="001";
constant  color4: std_logic_vector:="110";

signal 	hs1,vs1,fclk,cclk: std_logic;
signal 	fs: std_logic_vector(5 downto 0);
signal 	cc: std_logic_vector(4 downto 0);
signal 	ll: std_logic_vector(8 downto 0);
signal 	rgbp: std_logic_vector(3 downto 1);
signal	rgb: std_logic_vector(3 downto 1);

begin

rgb(1)<=rgbp(1) and hs1 and vs1;
rgb(2)<=rgbp(2) and hs1 and vs1;
rgb(3)<=rgbp(3) and hs1 and vs1;
fclk<=fs(5);
cclk<=cc(4);
hs<=hs1;
vs<=vs1;
r<=rgb(2);
g<=rgb(3);
b<=rgb(1);

process(clk)
begin
	if clk'event and clk='1' then
		if fs=51 then
			fs<="000000";
		else
			fs<=fs+1;
		end if;
	end if;
end process;

process(fclk)
begin
	if fclk'event and fclk='1' then
		if cc=27 then
			cc<="00000";
		else
			cc<=cc+1;
		end if;
	end if;
end process;

process(cclk)
begin
	if cclk'event and cclk='1' then
		if ll=481 then
			ll<="000000000";
		else
			ll<=ll+1;
		end if;
	end if;
end process;

process(cc, ll)
begin
	if cc>23 then 			--行同步
		hs1<='0';
	else hs1<='1';
	end if;
	if ll>479 then			--场同步
		vs1<='0';
	else vs1<='1';
	end if;
end process;

process(cc,ll,innum,innum1,innum2,innum3,innum4)
begin
	if cc>2 and cc<7 then
		if ll>60 and ll<101 and innum4(0)='0' then
			rgbp<=color1;
		elsif ll>180 and ll<221 and innum4(6)='0' then
			rgbp<=color1;
		elsif ll>300 and ll<341 and innum4(3)='0' then
			rgbp<=color1;
		elsif ll>60 and ll<202 then
			if (cc>2 and cc<4) and innum4(5)='0' then
				rgbp<=color1;
			elsif (cc>5 and cc<7) and innum4(1)='0' then
				rgbp<=color1;
			else rgbp<="000";
			end if;
		elsif ll>201 and ll<341 then
			if (cc>2 and cc<4) and innum4(4)='0' then
				rgbp<=color1;
			elsif (cc>5 and cc<7) and innum4(2)='0' then
				rgbp<=color1;
			else rgbp<="000";
			end if;
		elsif ll>350 and ll<370 then
			if cc>2 and cc<4 and innum(15)='1' then
				rgbp<=color1;
			elsif cc>3 and cc<5 and innum(14)='1' then
				rgbp<=color1;
			elsif cc>4 and cc<6 and innum(13)='1' then
				rgbp<=color1;
			elsif cc>5 and cc<7 and innum(12)='1' then
				rgbp<=color1;
			else rgbp<="000";
			end if;
		elsif ll>380 and ll<400 then
			if cc>2 and cc<4 and innum0(15)='1' then
				rgbp<=color1;
			elsif cc>3 and cc<5 and innum0(14)='1' then
				rgbp<=color1;
			elsif cc>4 and cc<6 and innum0(13)='1' then
				rgbp<=color1;
			elsif cc>5 and cc<7 and innum0(12)='1' then
				rgbp<=color1;
			else rgbp<="000";
			end if;
		end if;
		elsif cc>7 and cc<12 then
		if ll>60 and ll<101 and innum3(0)='0' then
			rgbp<=color2;
		elsif ll>180 and ll<221 and innum3(6)='0' then
			rgbp<=color2;
		elsif ll>300 and ll<341 and innum3(3)='0' then
			rgbp<=color2;
		elsif ll>60 and ll<202 then
			if (cc>7 and cc<9) and innum3(5)='0' then
				rgbp<=color2;
			elsif (cc>10 and cc<12) and innum3(1)='0' then
				rgbp<=color2;
			else rgbp<="000";
			end if;
		elsif ll>201 and ll<341 then
			if (cc>7 and cc<9) and innum3(4)='0' then
				rgbp<=color2;
			elsif (cc>10 and cc<12) and innum3(2)='0' then
				rgbp<=color2;
			else rgbp<="000";
			end if;
		elsif ll>350 and ll<370 then
			if cc>7 and cc<9 and innum(11)='1' then
				rgbp<=color2;
			elsif cc>8 and cc<10 and innum(10)='1' then
				rgbp<=color2;
			elsif cc>9 and cc<11 and innum(9)='1' then
				rgbp<=color2;
			elsif cc>10 and cc<12 and innum(8)='1' then
				rgbp<=color2;
			else rgbp<="000";
			end if;
			elsif ll>380 and ll<400 then
			if cc>7 and cc<9 and innum0(11)='1' then
				rgbp<=color2;
			elsif cc>8 and cc<10 and innum0(10)='1' then
				rgbp<=color2;
			elsif cc>9 and cc<11 and innum0(9)='1' then
				rgbp<=color2;
			elsif cc>10 and cc<12 and innum0(8)='1' then
				rgbp<=color2;
			else rgbp<="000";
			end if;
		end if;
	elsif cc>12 and cc<17 then
		if ll>60 and ll<101 and innum2(0)='0' then
			rgbp<=color3;
		elsif ll>180 and ll<221 and innum2(6)='0' then
			rgbp<=color3;
		elsif ll>300 and ll<341 and innum2(3)='0' then
			rgbp<=color3;
		elsif ll>60 and ll<202 then
			if (cc>12 and cc<14) and innum2(5)='0' then
				rgbp<=color3;
			elsif (cc>15 and cc<17) and innum2(1)='0' then
				rgbp<=color3;
			else rgbp<="000";
			end if;
		elsif ll>201 and ll<341 then
			if (cc>12 and cc<14) and innum2(4)='0' then
				rgbp<=color3;
			elsif (cc>15 and cc<17) and innum2(2)='0' then
				rgbp<=color3;
			else rgbp<="000";
			end if;
		elsif ll>350 and ll<370 then
			if cc>12 and cc<14 and innum(7)='1' then
				rgbp<=color3;
			elsif cc>13 and cc<15 and innum(6)='1' then
				rgbp<=color3;
			elsif cc>14 and cc<16 and innum(5)='1' then
				rgbp<=color3;
			elsif cc>15 and cc<17 and innum(4)='1' then
				rgbp<=color3;
			else rgbp<="000";
			end if;
		elsif ll>380 and ll<400 then
			if cc>17 and cc<19 and innum0(7)='1' then
				rgbp<=color4;
			elsif cc>18 and cc<20 and innum0(6)='1' then
				rgbp<=color4;
			elsif cc>19 and cc<21 and innum0(5)='1' then
				rgbp<=color4;
			elsif cc>20 and cc<22 and innum0(4)='1' then
				rgbp<=color4;
			else rgbp<="000";
			end if;
		end if;
	elsif cc>17 and cc<22 then
		if ll>60 and ll<101 and innum1(0)='0' then
			rgbp<=color4;
		elsif ll>180 and ll<221 and innum1(6)='0' then
			rgbp<=color4;
		elsif ll>300 and ll<341 and innum1(3)='0' then
			rgbp<=color4;
		elsif ll>60 and ll<202 then
			if (cc>17 and cc<19) and innum1(5)='0' then
				rgbp<=color4;
			elsif (cc>20 and cc<22) and innum1(1)='0' then
				rgbp<=color4;
			else rgbp<="000";
			end if;
		elsif ll>201 and ll<341 then
			if (cc>17 and cc<19) and innum1(4)='0' then
				rgbp<=color4;
			elsif (cc>20 and cc<22) and innum1(2)='0' then
				rgbp<=color4;
			else rgbp<="000";
			end if;
		elsif ll>350 and ll<370 then
			if cc>17 and cc<19 and innum(3)='1' then
				rgbp<=color4;
			elsif cc>18 and cc<20 and innum(2)='1' then
				rgbp<=color4;
			elsif cc>19 and cc<21 and innum(1)='1' then
				rgbp<=color4;
			elsif cc>20 and cc<22 and innum(0)='1' then
				rgbp<=color4;
			else rgbp<="000";
			end if;
		elsif ll>380 and ll<400 then
			if cc>17 and cc<19 and innum0(3)='1' then
				rgbp<=color4;
			elsif cc>18 and cc<20 and innum0(2)='1' then
				rgbp<=color4;
			elsif cc>19 and cc<21 and innum0(1)='1' then
				rgbp<=color4;
			elsif cc>20 and cc<22 and innum0(0)='1' then
				rgbp<=color4;
			else rgbp<="000";
			end if;
		else rgbp<="000";
		end if;	
	else rgbp<="000";
	end if;
end process;

end Behavioral;

⌨️ 快捷键说明

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