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

📄 vga4.vhd

📁 12MCS-51单片机原理与应用实例. 下一篇: 可编程控制器技术及应用(三菱系列). 上一篇: C51单片机应用与C语言程序设计--基于机器人工程对象的项目实践. Tags标签 ... www.r
💻 VHD
字号:
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity vga4 is
port(	clk50,mode_key,color:	in std_logic;		--50MHz
	 	hs :	out std_logic;
	 	vs :	out std_logic;
		r,g,b:	out std_logic);
end entity;
architecture bhv of vga4 is
	signal cclk:integer range 0 to 799;	--计数,单位象素
	signal vclk:integer range 0 to 524;	--计数,单位行
	signal hs2 :std_logic;				--计数,行的个数
	signal flag:std_logic_vector(2 downto 0);
	signal mode,flag2:std_logic_vector(1 downto 0);
	signal rgb :std_logic_vector(2 downto 0);
	signal clk25:std_logic;				--实际时钟
begin
----------------------------------时序------------------------------------------
process(clk50)
begin
if clk50'event and clk50='1' then
	clk25<=not clk25;
	end if;
end process;
process(clk25)
begin
if clk25'event and clk25='1' then
	cclk<=cclk+1;
	if cclk>=799 then
		cclk<=0;
	end if;				--800进制
	if (cclk>9)and(cclk<104) then 
		hs<='0';		--行同步,工业标准低电平
		hs2<='0';		
	else
		hs<='1';
		hs2<='1';
	end if;
	end if;
end process;
process(hs2)
begin
if hs2'event and hs2='1' then
	vclk<=vclk+1;
	if vclk=524 then
		vclk<=0;
	end if;
	if (vclk>2)and(vclk<5) then
		vs<='0';
	else
		vs<='1';
	end if;
end if;
end process;
-------------------------------控制颜色-----------------------------------------
process(color)
begin
if color'event and color='0' then
	if  flag="110" then flag<="000";
	else flag<=flag+1;
	end if;
end if;
end process;
process(flag)
begin
case flag is
	when "000"=>  rgb<="111";--白色
	when "001"=>  rgb<="101";--青色
	when "010"=>  rgb<="100";--红色
	when "011"=>  rgb<="001";--蓝色
	when "100"=>  rgb<="011";--品色
	when "101"=>  rgb<="110";--黄色
	when "110"=>  rgb<="010";--绿色
	when others=> rgb<="000";--黑色
end case;
end process;
------------------------------控制模式------------------------------------------
process(mode_key)
begin
if mode_key'event and mode_key='0' then
	if  flag2="11" then flag2<="00";
	else flag2<=flag2+1;
	end if;
end if;
end process;
process(flag2)
begin
case flag2 is
	when "00" =>  mode<="00";--全屏
	when "01" =>  mode<="01";--横条
	when "10" =>  mode<="10";--竖条
	when "11" =>  mode<="11";--棋盘
	when others=>  mode<="00";
end case;
end process;
------------------------------------送显----------------------------------------	
process(clk25)							

begin
if clk25'event and clk25='1' then
			
	if (cclk>152 and cclk<152+640)and(vclk>37 and vclk<37+480) then------回扫时影响显示
		if (mode="00") then				--全屏
			r<=rgb(2);g<=rgb(1);b<=rgb(0);
		elsif (mode="01") then				--横条形
			if (vclk<37+60) then
				r<='1';g<='0';b<='0';--红
			elsif ( vclk<37+120 ) then 
				r<='1';g<='0';b<='1';--青
			elsif ( vclk<37+180 ) then 
				r<='0';g<='1';b<='0';--绿
			elsif ( vclk<37+240 ) then 
				r<='0';g<='0';b<='1';--蓝
			elsif ( vclk<37+300 ) then 
				r<='1';g<='1';b<='0';--黄
			elsif ( vclk<37+360 ) then 
				r<='0';g<='1';b<='1';--品
			elsif ( vclk<37+420 ) then 
				r<='1';g<='1';b<='1';--白
			elsif ( vclk<37+480 ) then 
				r<='1';g<='0';b<='0';--红										
			end if;
		elsif (mode="10") then				--竖条形
			if (cclk<152+80) then
				r<='1';g<='0';b<='0';
			elsif (cclk<152+160) then
				r<='1';g<='0';b<='1';
			elsif (cclk<152+240) then
				r<='0';g<='1';b<='0';
			elsif (cclk<152+320) then
				r<='0';g<='0';b<='1';
			elsif (cclk<152+400) then
				r<='1';g<='1';b<='0';
			elsif (cclk<152+480) then
				r<='0';g<='1';b<='1';
			elsif (cclk<152+560) then
				r<='1';g<='1';b<='1';
			elsif (cclk<152+640) then
				r<='1';g<='0';b<='0';
			end if;	
		elsif (mode="11") then				--棋盘
			r<='1';g<='1';b<='1';
			if(vclk>37+68 and vclk<37+136) then			r<='0';g<='0';b<='0';
			elsif(vclk>37+135 and vclk<37+203) then 	r<='1';g<='1';b<='1';
			elsif(vclk>37+202 and vclk<37+270) then		r<='0';g<='0';b<='0';
			elsif(vclk>37+269 and vclk<37+337) then 	r<='1';g<='1';b<='1';
			elsif(vclk>37+336 and vclk<37+404) then		r<='0';g<='0';b<='0';
			elsif(vclk>37+403 and vclk<37+480) then 	r<='1';g<='1';b<='1';
			end if;
			if(cclk>152+106 and cclk<152+212) then		r<='0';g<='0';b<='0';
			elsif(cclk>152+318 and cclk<152+424) then   r<='0';g<='0';b<='0';
			elsif(cclk>152+529 and cclk<152+640) then   r<='0';g<='0';b<='0';
			end if;
			if(cclk>152+106+5 and cclk<152+212-5 ) then
				if(vclk>37+68 and vclk<37+136)or(vclk>37+203 and vclk<37+270)or(vclk>37+337 and vclk<37+404)then
				r<=rgb(2);g<=rgb(1);b<=rgb(0);
				end if;
			elsif(cclk>152+318+5 and cclk<152+424-5 ) then
				if(vclk>37+68 and vclk<37+136)or(vclk>37+203 and vclk<37+270)or(vclk>37+337 and vclk<37+404)then
				r<=rgb(2);g<=rgb(1);b<=rgb(0);
				end if;
			elsif(cclk>152+530+5 and cclk<152+640-5 ) then
				if(vclk>37+68 and vclk<37+136)or(vclk>37+203 and vclk<37+270)or(vclk>37+337 and vclk<37+404)then
				r<=rgb(2);g<=rgb(1);b<=rgb(0);
				end if;
			end if;
			else r<='0';g<='0';b<='0';--必须加,否则只闪一下
	end if;
end if;
end if;
end process;
end bhv;

⌨️ 快捷键说明

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