8-3编码器

8-3编码器

编码器是将2n个分离的信息代码以n个二进制码来表示。

8-3编码器的功能真值表

输入sw[n]

输出led[n]

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

0

1

0

0

0

1

0

0

0

0

0

1

0

0

0

1

0

0

0

0

0

1

0

0

0

0

1

1

0

0

0

1

0

0

0

0

1

0

0

0

0

1

0

0

0

0

0

1

0

1

0

1

0

0

0

0

0

0

1

1

0

1

0

0

0

0

0

0

0

1

1

1

其它

0

0

0

程序代码:

module encoder8_3(
    input [7:0] sw,
    output reg[2:0] led
    );
       always @ (sw)       //当sw发生改变时,输出led也跟着改变
              begin
                     case(sw)
                            8'b0000_0001: led = 3'b000 ;
                            8'b0000_0010: led = 3'b001 ;
                            8'b0000_0100: led = 3'b010 ;
                            8'b0000_1000: led = 3'b011 ;
                            8'b0001_0000: led = 3'b100 ;
                            8'b0010_0000: led = 3'b101 ;
                            8'b0100_0000: led = 3'b110 ;
                            8'b1000_0000: led = 3'b111 ;
                            default: led = 3'b000 ;
                     endcase
              end
endmodule

你可能感兴趣的:(FPGA,Verilog,HDL)