Code examples

Light a single LED

Light up the LED at row 3, column 5:

module led_one (
    output wire [7:0] row_n,
    output wire [7:0] col
);
    assign row_n = 8'b1111_1011;  // row 3 active (low)
    assign col   = 8'b0001_0000;  // column 5
endmodule

Multiplexing a pattern

module mux_matrix (
    input  wire        clk,
    output reg  [7:0]  row_n,
    output reg  [7:0]  col
);
    reg [2:0] sel = 0;
    reg [15:0] tick = 0;

    // pattern: each row turns on all its columns
    always @(posedge clk) begin
        tick <= tick + 1;
        if (tick == 0) begin
            sel   <= sel + 1;
            row_n <= ~(8'b1 << sel);
            col   <= 8'hFF;
        end
    end
endmodule

Resulting refresh: 12 MHz / 65 536 / 8 ≈ 22 Hz per row → too slow, you'll see flicker! Reduce the divider to clear 60 Hz.

Comments

...