![]() | 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.