10.8 8位寄存器
/
module reg8(qout,in,clk,clear);
output [7:0] qout;reg [7:0] qout;
input [7:0] in;
input clk,clear;
always @ (posedge clk or posedge clear)
begin
if (clear) qout=8'd0;
else qout=in;
end
endmodule
10.11 阻塞赋值方式描述的移位寄存器1
/
output q3,q2,q1,q0;
reg q3,q2,q1,q0;
input clk,din;
always @ (posedge clk)
begin
q3=q2;
q2=q1;
q1=q0;
q0=din;
end
endmodule
10.12 阻塞赋值方式描述的移位寄存器2
/
output q3,q2,q1,q0;
reg q3,q2,q1,q0;
input clk,din;
always @ (posedge clk)
begin
q3=q2;
q1=q0;
q2=q1;
q0=din;
end
endmodule
10.13 阻塞赋值方式描述的移位寄存器3
/
output q3,q2,q1,q0;
reg q3,q2,q1,q0;
input clk,din;
always @ (posedge clk)
begin
q0=din;
q1=q0;
q2=q1;
q3=q2;
end
endmodule
10.14 非阻塞赋值方式描述的移位寄存器
/
output q3,q2,q1,q0;
reg q3,q2,q1,q0;
input clk,din;
always @ (posedge clk)
begin
q3<=q2;
q2<=q1;
q1<=q0;
q0<=din;
end
endmodule
10.15 长帧同步时钟的产生
/
parameter delay=8;
input clk;
output strb;
reg strb;
reg [7:0] count;
always @ (posedge clk)
begin
if (count==255) count=0;
else count=count+1;
end
always @ (posedge clk)
begin
if(count<(delay-1)) strb=1;
else strb=0;
end
endmodule
10.16 引入了D触发器的长帧同步时钟的产生
/
parameter delay=8;
output strb;
reg strb;
reg [7:0] count;
reg temp;
always @ (posedge clk)
begin
if(count==255) count=8'd0;
else count=count+8'd1;
end
always @ (posedge clk)
begin
strb=temp;
end
always @ (posedge clk)
begin
if(count<(delay-1)) temp=1'b1;
else temp=1'b0;
end
endmodule
11.1 数字跑表
/
input clk,clr,pause;
output [3:0] msh,msl,sh,sl,mh,ml;
reg [3:0] msh,msl,sh,sl,mh,ml;
reg cnt1,cnt2;
always @ (posedge clk or posedge clr)
begin
if(clr) begin {msh,msl}=8'h00;cnt1<=0; end
else if(!pause)
begin
if(msl==9) begin msl<=0; if(msh==9) begin msh<=0;cnt1<=1; end
else msh=msh+1;
end
else begin msl=msl+1; cnt1<=0; end
end
end
always @ (posedge cnt1 or posedge clr)
begin
if(clr) begin {sh,sl}<=8'h00; cnt2<=0; end
else if(sl==9)
begin sl<=0;
if(sh==5) begin sh<=0; cnt2<=1; end
else begin sh<=sh+1; cnt2<=0; end
end
else begin sl<=sl+1; cnt2<=0; end
end
always @ (posedge cnt2 or posedge clr)
begin
if(clr) begin {mh,ml}=8'h00; end
else if(ml==9) begin
ml<=0;
if(mh==5) mh<=0;
else mh<=mh+1;
end
else ml<=ml+1;
end
endmodule
11.2 4位数字频率计控制模块
/
output count_en,count_clr,load;
input clk,rst;
reg count_en,load;
always @ (posedge clk)
begin
if(rst) begin count_en=0; load=1; end
else begin
count_en=~count_en;
load=~count_en;
end
end
assign count_clr=~clk&load;
endmodule
11.3 4位数字频率计计数子模块
/
output [3:0] out;
reg [3:0] out;
output cout;
input en,clk,clr;
always @ (posedge clk or posedge clr)
begin
if(clr) out=0;