| 1 |
`default_nettype none |
| 2 |
(* top *) |
| 3 |
module top |
| 4 |
( |
| 5 |
input wire rst_i, |
| 6 |
input wire clk, |
| 7 |
|
| 8 |
output wire LCD_CLK, |
| 9 |
output wire LCD_HYNC, |
| 10 |
output wire LCD_SYNC, |
| 11 |
output wire LCD_DEN, |
| 12 |
output wire [`R_MSB:0] LCD_R, |
| 13 |
output wire [`G_MSB:0] LCD_G, |
| 14 |
output wire [`B_MSB:0] LCD_B |
| 15 |
); |
| 16 |
|
| 17 |
wire rst = rst_i ^ `INV_BTN; |
| 18 |
wire pixel_clk; |
| 19 |
wire gnd; |
| 20 |
assign gnd = 1'b0; |
| 21 |
|
| 22 |
clock_pll clock_pll( |
| 23 |
.clk(clk), |
| 24 |
.rst(rst), |
| 25 |
.write_clk(), |
| 26 |
.pixel_clk(pixel_clk)); |
| 27 |
|
| 28 |
|
| 29 |
assign LCD_CLK = pixel_clk; |
| 30 |
|
| 31 |
reg [15:0] pixel_count; |
| 32 |
reg [15:0] line_count; |
| 33 |
|
| 34 |
display display( |
| 35 |
.pixel_clk(pixel_clk), |
| 36 |
.rst(rst), |
| 37 |
.x(pixel_count), |
| 38 |
.y(line_count), |
| 39 |
.LCD_HYNC(LCD_HYNC), |
| 40 |
.LCD_SYNC(LCD_SYNC), |
| 41 |
.LCD_DEN(LCD_DEN) |
| 42 |
); |
| 43 |
|
| 44 |
wire [8:0] dout; |
| 45 |
reg [11:0] addr; |
| 46 |
|
| 47 |
image_rom image( |
| 48 |
.clk(pixel_clk), |
| 49 |
.reset(!rst), |
| 50 |
.ad(addr), |
| 51 |
.data(dout) |
| 52 |
); |
| 53 |
|
| 54 |
wire [7:0] vmem_start_col; |
| 55 |
wire [7:0] vmem_start_row; |
| 56 |
assign vmem_start_col = pixel_count - `START_X; |
| 57 |
assign vmem_start_row = line_count - `START_Y; |
| 58 |
|
| 59 |
always @(negedge pixel_clk) begin |
| 60 |
addr = {vmem_start_row[7:2], vmem_start_col[7:2]}; |
| 61 |
end |
| 62 |
|
| 63 |
wire is_out_x = pixel_count < `START_X || pixel_count >= `STOP_X; |
| 64 |
wire is_out_y = line_count < `START_Y || line_count >= `STOP_Y; |
| 65 |
|
| 66 |
reg [15:0] color; |
| 67 |
always @(negedge pixel_clk) begin |
| 68 |
if (is_out_x || is_out_y) begin |
| 69 |
color = line_count + pixel_count; |
| 70 |
end else begin |
| 71 |
color = {dout[8:4], dout[8:3], dout[8:4]}; |
| 72 |
end |
| 73 |
end |
| 74 |
|
| 75 |
assign LCD_R = LCD_DEN ? color[4:0] >> (4 - `R_MSB) : 0; |
| 76 |
assign LCD_G = LCD_DEN ? color[10:5] >> (5 - `G_MSB) : 0; |
| 77 |
assign LCD_B = LCD_DEN ? color[15:11] >> (4 - `B_MSB) : 0; |
| 78 |
|
| 79 |
endmodule |
| 80 |
|