module clk2
(
input rst,
input clk,
input [7:0]in,
input [2:0]sel,
output reg out1,
output [7:0]out2
);
reg jcq;
always@(posedge clk)
begin
if(~rst)
jcq<=0;
else
jcq<=in;
end
always@(posedge clk)
begin
if(~rst)
out1<=1'b0;
else case(sel)
3'd0:out1<=in[0];
3'd1:out1<=in[1];
3'd2:out1<=in[2];
3'd3:out1<=in[3];
3'd4:out1<=in[4];
3'd5:out1<=in[5];
3'd6:out1<=in[6];
3'd7:out1<=in[7];
default:;
endcase
end
assign out2[7:0]={out2[6:0],in};
endmodule
测试:
`timescale 1ns/1ps
module clk2text();
reg clk;
reg rst;
reg [7:0]in;
reg [2:0]sel;
initial
begin
rst=0;
#100 rst=1;
#10000 $stop;
end
initial
begin
sel=0;
#100 sel=3'd1;
#100 sel=3'd2;
#100 sel=3'd2;
#100 sel=3'd3;
#100 sel=3'd4;
#100 sel=3'd5;
#100 sel=3'd6;
#100 sel=3'd7;
end
initial
begin
clk=0;
end
initial
begin
in=0;
#100 in=8'b00000001;
#100 in=8'b00000010;
end
always #5 clk<=~clk;
clk2
clk2_inst
(
.clk(clk),
.rst(rst),
.in(in),
.sel(sel),
.out1(),
.out2()
);
endmodule