Verilog HDL:双向引脚

author-image

作者

此示例在 Verilog HDL 中实施了时钟控制双向引脚。OE 的值决定了 bidir 是馈入 inp 的输入,还是处于输出 b 值的三态模式。
有关在项目中使用此示例的更多信息,请访问:

bidir.v
module bidirec (oe, clk, inp, outp, bidir);

// Port Declaration

input   oe;
input   clk;
input   [7:0] inp;
output  [7:0] outp;
inout   [7:0] bidir;

reg     [7:0] a;
reg     [7:0] b;

assign bidir = oe ? a : 8'bZ ;
assign outp  = b;

// Always Construct

always @ (posedge clk)
begin
    b <= bidir;
    a <= inp;
end

endmodule