Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module top (c, l, a, d, r, w, up, dn);
- input wire c; // clock
- output wire [7:0] l; // leds
- output wire[16:0] a; // address
- inout wire [7:0] d; // data
- output wire r; // read
- output wire w; // write
- input wire up; // up button
- input wire dn; // down button
- // Clock
- wire clk1;
- wire clk2;
- wire clkOk;
- pll pll0 (.CLK(c), .CLKOP(clk1), .CLKOK(clk2), .LOCK(clkOk));
- // Main module
- sram_read_write sramscope (.clock(c), .address(a), .data(d), .read(r), .write(w), .leds(l), .up(up), .down(dn));
- endmodule
- module sram_read_write (clock, address, data, read, write, leds, up, down);
- // I/O
- input wire clock;
- output reg[16:0] address;
- inout [7:0] data;
- output reg [7:0] leds;
- output reg write;
- output reg read;
- input wire up;
- input wire down;
- // Local variables
- reg [3:0] counter;
- reg [16:0] laddress;
- reg [7:0] ldata;
- reg operation;
- // Setup
- initial
- begin
- counter[3:0] = 4'b0;
- laddress[16:0] = 17'b1_1111_1111_1111_1111;
- ldata[7:0] = 8'b1111_1111;
- operation = 0;
- end
- // Assignments
- assign data = write ? ldata : 8'b0;
- // Main loop
- always @(posedge clock)
- begin
- // Assign the leds so the value stored there shows up
- leds[7:0] = ldata[7:0];
- // Have we gotten to 1 yet?
- counter <= counter + 4'b1;
- if (counter > 4'b1)
- begin
- // Turn off any read prior read or write as they only strobe two clocks
- write <= 1'b0;
- read <= 1'b0;
- end
- // Have we gotten to 10 yet?
- if (counter > 9)
- begin
- // Ready to perform the next operation
- // Note: For the first 255 operations, we write from 0..255 in SRAM
- // Note: After that, we respond to up/dn presses to display the next or previous address
- // Reset the counter
- counter <= 1'b0;
- // Are we writing or reading?
- if (operation == 1'b0)
- begin
- // We're writing to the SRAM
- // Increase our address
- laddress[16:0] <= laddress[16:0] + 17'b1;
- address[16:0] <= laddress[16:0];
- // Shift the data value
- ldata <= (ldata - 1'b1);
- // Strobe write
- write <= 1'b1;
- // If we're done, switch operation
- if (ldata[7:0] == 7'b0)
- begin
- operation <= 1'b1;
- end
- end else begin
- // We're displaying what's in the SRAM
- // Are we going up?
- if (up == 1'b1)
- begin
- // They're going up in address
- laddress <= laddress + 1'b1;
- end
- // Are we going down?
- if (down == 1'b1)
- begin
- // They're going down in address
- laddress <= laddress - 1'b1;
- end
- // Strobe read
- read <= 1'b1;
- end
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement