vga显示驱动程序可分为扫描行列和行列同步两个部分
//注意:只有在有效区域内给vga赋值才会有颜色变化
assign vga_b = isready ? vga_s[7:0] :8'd0; assign vga_g = isready ? vga_s[15:8] :8'd0; assign vga_r = isready ? vga_s[23:16]:8'd0;
扫描行列
/*********************************/ //扫描x,y; reg [10:0] count_x;//计数列 reg [10:0] count_y;//计数行 always @(posedge clk or negedge rst_n) if(!rst_n) count_x <= 1'd0; else if(count_x == 11'd1056) count_x <= 1'd0; else count_x <= count_x + 1'b1; always @(posedge clk or negedge rst_n) if(!rst_n) count_y <= 1'd0; else if(count_y == 11'd625) count_y <= 1'd0; else if(count_x == 11'd1056) count_y <= count_y +1'd1; else count_y <= count_y; /************************************/
//行列同步 这个由vga时序所决定的
/************************************/ //行列同步 assign VGA_VS = (count_y <= 11'd3) ? 1'b0 : 1'b1; assign VGA_HS = (count_x <= 11'd80)? 1'b0 : 1'b1; assign VGA_SYNC_N = (count_y <= 11'd3) ? 1'b0 : 1'b1; assign VGA_BLANK_N = (count_x <= 11'd80)? 1'b0 : 1'b1; /**************************************/
另外要把x,y的坐标提取出来
//x,y坐标 wire loca_x,loca_y; assign loca_x = isready ? count_x-11'd240 : 11'd0; assign loca_y = isready ? count_y-11'd24 : 11'd0; /*****************************************/
//显示彩条颜色
//显示颜色 reg [23:0] vga_s; always @(posedge clk or negedge rst_n) if(!rst_n) vga_s <= 24'hffffff; else if(count_y> 11'd0 && count_y <= 11'd100) vga_s <= 24'hff0000; else if(count_y >11'd100 && count_y <= 11'd200) vga_s <= 24'hff8c00; else if(count_y >11'd200 && count_y <= 11'd300) vga_s <= 24'hffff00; else if(count_y >11'd300 && count_y <= 11'd400) vga_s <= 24'h00fa9a; else if(count_y >11'd400 && count_y <= 11'd500) vga_s <= 24'h40e0d0; else if(count_y >11'd500 && count_y <= 11'd600) vga_s <= 24'h0000ff; /**********************************************/ assign VGA_CLK = clk;