module vga640x480( input clk, input rst, output [7:0] LED, output reg hsync, output reg vsync, output [3:0] r, output [3:0] g, output [3:0] b );
reg clk25; reg [9:0] horizontal_counter; reg [9:0] vertical_counter;
reg [9:0] X; reg [9:0] Y;
wire [7:0] red; wire [7:0] green; wire [7:0] blue;
assign r[3:0] = ((horizontal_counter >= 144) && (horizontal_counter < 784) && (vertical_counter >=39) && (vertical_counter < 519)) ? red : 4'b000; assign g[3:0] = ((horizontal_counter >= 144) && (horizontal_counter < 784) && (vertical_counter >=39) && (vertical_counter < 519)) ? green : 4'b000; assign b[3:0] = ((horizontal_counter >= 144) && (horizontal_counter < 784) && (vertical_counter >=39) && (vertical_counter < 519)) ? blue : 4'b000; assign red = ((horizontal_counter >= 144)&&(horizontal_counter < 344) ) ? 4'b1111 : 4'b0000; assign green = ((horizontal_counter >= 344)&&(horizontal_counter < 544) ) ? 4'b1111 : 4'b0000; assign blue = ((horizontal_counter >= 544)&&(horizontal_counter < 784) ) ? 4'b1111 : 4'b0000;
always @(posedge clk) begin
if (clk25 == 0) begin clk25 <= 1; end else begin clk25 <= 0; end end
always @(posedge clk25) begin if ((horizontal_counter > 0) && (horizontal_counter < 97))// -- 96+1 begin hsync <= 0; end else begin hsync <= 1; end if ((vertical_counter > 0 ) && (vertical_counter < 3 )) //-- 2+1 begin vsync <= 0; end else begin vsync <= 1; end horizontal_counter <= horizontal_counter+1; if (horizontal_counter == 800) begin vertical_counter <= vertical_counter+1; horizontal_counter <= 0; end if (vertical_counter == 521) begin vertical_counter <= 0; end end
endmodule |