打印
[Verilog HDL]

SR触发器

[复制链接]
1138|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gaochy1126|  楼主 | 2022-12-29 21:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
module cy4(input S,
           input R,
           input clk,
           input rst_n,
           output reg Q
        );
always @(posedge clk or negedge rst_n)
  if(!rst_n) Q <= 1'b0;
  else
    case({S,R})
      2'b00: Q <= Q;
      2'b01: Q <= 1'b0;
      2'b10: Q <= 1'b1;
      2'b11: Q <= 1'bx;
    endcase

endmodule
测试脚本代码:
`timescale 1 ns/ 1 ps
module cy4_vlg_tst();
reg R;
reg S;
reg clk;
reg rst_n;
wire Q;

cy4 i1 (
.Q(Q),
.R(R),
.S(S),
.clk(clk),
.rst_n(rst_n)
);
initial
begin
clk = 0;
rst_n = 0;

10;

rst_n = 1;
S = 0;
R = 0;

50;

S = 0;
R = 1;

50;

S = 1;
R = 0;

50;

S = 1;
R = 1;

50;

<span id="MathJax-Element-1-Frame" tabindex="0" data-mathml="stop;" role="presentation" style="box-sizing: border-box; border: 0px; font: inherit; vertical-align: baseline; position: relative;">stop;stop;display(“Running testbench”);
end
always #10 clk = ~clk;
endmodule


使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:这个社会混好的两种人:一是有权有势,二是没脸没皮的。

1025

主题

11271

帖子

24

粉丝