본문 바로가기

Verilog/HDLbits

[HDLBits] Always nolatches

 

1. 문제 및 설명

  • PS/2 키보드의 스캔코드를 처리하는 회로를 만든다고 할 때, 마지막으로 받은 두 바이트의 스캔코드를 기반으로 키보드의 방향키가 눌렸는지 여부를 표시해야 한다.
    1. 회로는 하나의16비트 입력과 네 개의 출력을 가진다. 이 4가지 스캔코드를 인식하여 해당되는 출력을 1로 만들어 주어야 한다.
    2. 래치를 만들지 않기 위해서는 모든 가능한 조건에서 모든 출력 신호가 반드시 값이 할당되어야 한다.
     

2. 모듈 정의

module top_module (
    input [15:0] scancode,
    output reg left,
    output reg down,
    output reg right,
    output reg up  );

 

 

 

3. 답

module top_module (
    input [15:0] scancode,
    output reg left,
    output reg down,
    output reg right,
    output reg up  ); 
    
    always@(*)
        begin
            up = 1'b0; down = 1'b0; left = 1'b0; right = 1'b0;
            case(scancode)
                16'he06b: left = 1'b1;
                16'he072: down = 1'b1;
                16'he074: right = 1'b1; 
                16'he075: up = 1'b1;
            endcase
        end

endmodule
 

'Verilog > HDLbits' 카테고리의 다른 글

[HDLBits] Reduction  (0) 2025.12.07
[HDLBits] Conditional  (0) 2025.12.07
[HDLBits] Always casez  (0) 2025.12.07
[HDLBits] Always case2  (0) 2025.11.24
[HDLBits] Always case  (0) 2025.11.23