vga显示彩条

时间:2023-03-08 16:57:41

vga显示驱动程序可分为扫描行列和行列同步两个部分

//注意:只有在有效区域内给vga赋值才会有颜色变化

assign  vga_b        = isready ? vga_s[:]  :'d0;
assign vga_g = isready ? vga_s[:] :'d0;
assign vga_r = isready ? vga_s[:]:'d0;

扫描行列

/*********************************/
//扫描x,y;
reg [:] count_x;//计数列
reg [:] count_y;//计数行
always @(posedge clk or negedge rst_n)
if(!rst_n)
count_x <= 'd0;
else if(count_x == 'd1056)
count_x <= 'd0;
else
count_x <= count_x + 'b1;
always @(posedge clk or negedge rst_n)
if(!rst_n)
count_y <= 'd0;
else if(count_y == 'd625)
count_y <= 'd0;
else if(count_x == 'd1056)
count_y <= count_y +'d1;
else
count_y <= count_y; /************************************/

//行列同步 这个由vga时序所决定的

/************************************/
//行列同步
assign VGA_VS = (count_y <= 'd3) ? 1'b0 : 'b1;
assign VGA_HS = (count_x <= 'd80)? 1'b0 : 'b1;
assign VGA_SYNC_N = (count_y <= 'd3) ? 1'b0 : 'b1;
assign VGA_BLANK_N = (count_x <= 'd80)? 1'b0 : 'b1;
/**************************************/

另外要把x,y的坐标提取出来

//x,y坐标
wire loca_x,loca_y;
assign loca_x = isready ? count_x-'d240 : 11'd0;
assign loca_y = isready ? count_y-'d24 : 11'd0;
/*****************************************/

//显示彩条颜色

//显示颜色
reg [:] vga_s;
always @(posedge clk or negedge rst_n)
if(!rst_n)
vga_s <= 'hffffff;
else if(count_y> 'd0 && count_y <= 11'd100)
vga_s <= 'hff0000;
else if(count_y >'d100 && count_y <= 11'd200)
vga_s <= 'hff8c00;
else if(count_y >'d200 && count_y <= 11'd300)
vga_s <= 'hffff00;
else if(count_y >'d300 && count_y <= 11'd400)
vga_s <= 'h00fa9a;
else if(count_y >'d400 && count_y <= 11'd500)
vga_s <= 'h40e0d0;
else if(count_y >'d500 && count_y <= 11'd600)
vga_s <= 'h0000ff; /**********************************************/
assign VGA_CLK = clk;