- `timescale 10ns/1ns
- module task01(x_out, x_clk, x_en);
- output x_out, x_clk, x_en;
- reg d_out, d_clk, d_en;
- reg[7:0] i;
- parameter default_clock = 1;
- assign x_out = d_out;
- assign x_clk = d_clk;
- assign x_en = d_en;
- initial
- begin
- d_en = 1;
- d_out = 1;
- d_clk = 1; //put you code here
- #5;
- //write1bit(10, 0);
- write8bit(0, 8'b10101010);
- #5;
- end
- task write1bit(input integer clk_cycle, input integer data);
- begin
- if (clk_cycle == 0)
- begin
- d_clk = 0;
- d_out = data%2;
- #default_clock d_clk = 1;
- #default_clock d_clk = 0;
- end
- else
- begin
- d_clk = 0;
- d_out = data%2;
- #clk_cycle d_clk = 1;
- #clk_cycle d_clk = 0;
- end
- end
- endtask
- task write8bit(input integer clk_cycle, input integer data);
- begin
- if(clk_cycle == 0)
- begin
- for(i = 0; i < 8; i = i+1)
- begin
- d_clk = 1'b0;
- d_out = (data >> i)%2;
- #default_clock;
- d_clk = ~d_clk;
- #default_clock;
- end
- end
- else
- begin
- for(i = 0; i < 8; i = i+1)
- begin
- d_clk = 1'b0;
- d_out = (data >> i)%2;
- #clk_cycle;
- d_clk = ~d_clk;
- #default_clock;
- end
- end
- end
- endtask
- endmodule
复制代码 |