2018-08-13 22:17:36 +00:00
|
|
|
|
2018-02-03 20:20:56 +00:00
|
|
|
`include "hvsync_generator.v"
|
|
|
|
`include "digits10.v"
|
2018-06-01 17:33:37 +00:00
|
|
|
`include "ram.v"
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-10-01 16:30:47 +00:00
|
|
|
/*
|
|
|
|
Displays a grid of digits on the CRT using a RAM module.
|
|
|
|
*/
|
|
|
|
|
2018-02-15 18:31:32 +00:00
|
|
|
module test_ram1_top(clk, reset, hsync, vsync, rgb);
|
2018-02-07 00:07:40 +00:00
|
|
|
|
|
|
|
input clk, reset;
|
|
|
|
output hsync, vsync;
|
|
|
|
output [2:0] rgb;
|
|
|
|
|
2018-02-03 20:20:56 +00:00
|
|
|
wire display_on;
|
|
|
|
wire [8:0] hpos;
|
|
|
|
wire [8:0] vpos;
|
|
|
|
|
|
|
|
wire [9:0] ram_addr;
|
|
|
|
wire [7:0] ram_read;
|
|
|
|
reg [7:0] ram_write;
|
|
|
|
reg ram_writeenable = 0;
|
|
|
|
|
2018-02-21 19:32:11 +00:00
|
|
|
// RAM to hold 32x32 array of bytes
|
2018-06-01 17:33:37 +00:00
|
|
|
RAM_sync ram(
|
2018-02-03 20:20:56 +00:00
|
|
|
.clk(clk),
|
|
|
|
.dout(ram_read),
|
|
|
|
.din(ram_write),
|
|
|
|
.addr(ram_addr),
|
|
|
|
.we(ram_writeenable)
|
|
|
|
);
|
|
|
|
|
|
|
|
hvsync_generator hvsync_gen(
|
|
|
|
.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.hsync(hsync),
|
|
|
|
.vsync(vsync),
|
|
|
|
.display_on(display_on),
|
|
|
|
.hpos(hpos),
|
|
|
|
.vpos(vpos)
|
|
|
|
);
|
2018-02-21 19:32:11 +00:00
|
|
|
|
|
|
|
wire [4:0] row = vpos[7:3]; // 5-bit row, vpos / 8
|
|
|
|
wire [4:0] col = hpos[7:3]; // 5-bit column, hpos / 8
|
|
|
|
wire [2:0] rom_yofs = vpos[2:0]; // scanline of cell
|
|
|
|
wire [4:0] rom_bits; // 5 pixels per scanline
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-02-21 19:32:11 +00:00
|
|
|
wire [3:0] digit = ram_read[3:0]; // read digit from RAM
|
|
|
|
wire [2:0] xofs = hpos[2:0]; // which pixel to draw (0-7)
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-02-21 19:32:11 +00:00
|
|
|
assign ram_addr = {row,col}; // 10-bit RAM address
|
|
|
|
|
|
|
|
// digits ROM
|
2018-02-03 20:20:56 +00:00
|
|
|
digits10_case numbers(
|
|
|
|
.digit(digit),
|
2018-02-21 19:32:11 +00:00
|
|
|
.yofs(rom_yofs),
|
|
|
|
.bits(rom_bits)
|
2018-02-03 20:20:56 +00:00
|
|
|
);
|
|
|
|
|
2018-02-21 19:32:11 +00:00
|
|
|
// extract bit from ROM output
|
2018-02-03 20:20:56 +00:00
|
|
|
wire r = display_on && 0;
|
2018-02-21 19:32:11 +00:00
|
|
|
wire g = display_on && rom_bits[~xofs];
|
2018-02-03 20:20:56 +00:00
|
|
|
wire b = display_on && 0;
|
|
|
|
assign rgb = {b,g,r};
|
|
|
|
|
2018-02-21 19:32:11 +00:00
|
|
|
// increment the current RAM cell
|
2018-02-03 20:20:56 +00:00
|
|
|
always @(posedge clk)
|
2018-02-21 19:32:11 +00:00
|
|
|
case (hpos[2:0])
|
|
|
|
// on 7th pixel of cell
|
|
|
|
6: begin
|
|
|
|
// increment RAM cell
|
|
|
|
ram_write <= (ram_read + 1);
|
|
|
|
// only enable write on last scanline of cell
|
2019-08-02 03:10:31 +00:00
|
|
|
ram_writeenable <= display_on && rom_yofs == 7;
|
2018-02-21 19:32:11 +00:00
|
|
|
end
|
|
|
|
// on 8th pixel of cell
|
|
|
|
7: begin
|
|
|
|
// disable write
|
|
|
|
ram_writeenable <= 0;
|
|
|
|
end
|
|
|
|
endcase
|
2021-07-09 18:57:54 +00:00
|
|
|
|
2018-02-03 20:20:56 +00:00
|
|
|
endmodule
|