HOME       UP       PREV       FURTHER NOTES       NEXT (Counter/Timer Block)  

Keyboard Controller (scan multiplexed type).

Resistive switches shown (most keyboards and touch screens now use capacitive rather than resistive).

  output [3:0] scankey;
  input pressed;
  reg int_enable, pending;
  reg [3:0] scankey, pkey;

  always @(posedge clk) begin
     if (!pressed) pkey <= scankey;
     else scankey <= scankey + 1;
     
     if (hwen) int_enable <= wdata[0]
     pressed1 <= pressed;
     if (!pressed1 && pressed) pending <= 1;
     if (hren) pending <= 0;
     end
  assign interrupt = pending && int_enable;
  assign rdata = { 28'b0, pkey };

This keyboard scanner generates an interrupt on each key press. In practice, scan more slowly and use extra register on asynchronous input pressed (metastability). Also, have more than one input wire (use a close to square array).

Typically use a separate microcontroller to scan keyboard.

Standard PC keyboard generates an output byte on press and release and implements a FIFO in case MS DOS busy.


34: (C) 2008-15, DJ Greaves, University of Cambridge, Computer Laboratory.