Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 1ps
- module kypdDecoder(
- input logic clk,
- input logic n_rst,
- inout logic [7:0] ja, // [7:4] rows, [3:0] columns
- output logic [15:0] pressed
- );
- logic [3:0] cols, rows;
- assign rows = ja[7:4]; // input
- assign ja[3:0] = cols; // output
- logic [1:0] colIndex;
- always_ff @(posedge clk) begin
- if(n_rst == 1'b0) begin
- // Zero is shifted around
- cols <= 4'b1110;
- colIndex <= 2'd0;
- pressed <= 16'b0;
- end else begin
- // Write pressed for entire row
- pressed[colIndex * 4 +: 4] = ~rows;
- // Shift zero and increment index
- cols <= {cols[2:0], 1'b1};
- colIndex <= colIndex + 1;
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement