VGA颜色分块显示

项目名称

Vga不同颜色分块显示

具体要求

显示任意颜色,例如上下平分屏幕,红绿上下显示。屏幕四等份平分,顺时针显示红、绿、蓝、黄。

设计架构

这个小项目在vga显示上改进的,比较简单,四等份平分需要注意 每一部分的长宽都必须相等,笔者计算每部分的计数值画的草图如下,在显示区域之外为消隐区,  不再多说直接上代码

                      

代码设计

红绿显示,部分代码参考上个项目,必须在显示标志区内才能正常显示

//显示区标志
always@(*)
	if(!rst_n)
		flag<=0;
	else if((cnt1>=11'd144 && cnt1<11'd784) && (cnt2>=11'd35 && cnt2<11'd515))
		flag<=1;
	else 	
		flag<=0;
//--------------------红绿显示-------------------------//		
always@(posedge clk or negedge rst_n)
	if(!rst_n)
		vga_rgb<=0;
	else if(flag)begin
		if(cnt2>=11'd35 && cnt2<=11'd274)
			vga_rgb<=green;
		else if(cnt2>=11'd275 && cnt2<=11'd514)
			vga_rgb<=red;
		else
			vga_rgb<=0;
	end
	else
		vga_rgb<=0;

 四等份显示代码

//显示区标志
always@(*)
	if(!rst_n)
		flag<=0;
	else if((cnt1>=11'd144 && cnt1<11'd784) && (cnt2>=11'd35 && cnt2<11'd515))
		flag<=1;
	else 	
		flag<=0;

always@(posedge clk or negedge rst_n)
	if(!rst_n)
		vga_rgb<=0;
	else if(flag)begin
		if((cnt1>=11'd144 && cnt1<=11'd463) && (cnt2>=11'd35 && cnt2<=11'd274))
			vga_rgb<=red;
		else if((cnt1>=11'd464 && cnt1<=11'd783) && (cnt2>=11'd35 && cnt2<=11'd274))
			vga_rgb<=green;
		else if((cnt1>=11'd464 && cnt1<=11'd783) && (cnt2>=11'd275 && cnt2<=11'd514))
			vga_rgb<=blue;
		else if((cnt1>=11'd144 && cnt1<=11'd463) && (cnt2>=11'd275 && cnt2<=11'd514))
			vga_rgb<=yellow;
		else
			vga_rgb<=0;
	end
	else
		vga_rgb<=0;

显示结果

             

猜你喜欢

转载自blog.csdn.net/weixin_43533751/article/details/106986109
VGA