Advertisement
AkitoApocalypse

Untitled

May 24th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. `timescale 1ns / 1ps
  2.  
  3. module kypdDecoder(
  4. input logic clk,
  5. input logic n_rst,
  6. inout logic [7:0] ja, // [7:4] rows, [3:0] columns
  7. output logic [15:0] pressed
  8. );
  9. logic [3:0] cols, rows;
  10. assign rows = ja[7:4]; // input
  11. assign ja[3:0] = cols; // output
  12.  
  13. logic [1:0] colIndex;
  14. always_ff @(posedge clk) begin
  15. if(n_rst == 1'b0) begin
  16. // Zero is shifted around
  17. cols <= 4'b1110;
  18. colIndex <= 2'd0;
  19. pressed <= 16'b0;
  20. end else begin
  21. // Write pressed for entire row
  22. pressed[colIndex * 4 +: 4] = ~rows;
  23.  
  24. // Shift zero and increment index
  25. cols <= {cols[2:0], 1'b1};
  26. colIndex <= colIndex + 1;
  27. end
  28. end
  29. endmodule
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement