1、同步复位和异步复位的这两个代码应该怎么描述?
2、交通灯的这段代码能解释一下吗?主要解释一下倒计时的部分,并且给出红黄绿的状态转化图。
module jtd(clk,rst,seg7,out);
input clk,rst;
output[5:0]out;
output[6:0]seg7;
parameter s0=0,s1=1,s2=2,s3=3;
reg[5:0]c_state,next_state,out;
reg[6:0]seg7;
reg[31:0]cnt1;
reg[3:0]cnt2;
reg clk10hz;
always @ (posedge clk)
begin
if(cnt1==9999999)
begin
cnt1<=0;
clk10hz<=~clk10hz;
end
else
cnt1<=cnt1+1;
end
always@(posedge clk10hz, negedge rst)
begin
if(!rst)c_state<=s0;
else if(cnt2==9)
begin cnt2<=0;c_state<=next_state; end
else
cnt2<=cnt2+1;
end
always@(c_state)begin
case(c_state)
s0:begin next_state<=s1;out<=6'b010100;end
s1:begin next_state<=s2;out<=6'b001100;end
s2:begin next_state<=s3;out<=6'b100010;end
s3:begin next_state<=s0;out<=6'b100001;end
endcase
end
always@(cnt2)
begin
case(cnt2)
0:seg7=7'b0111111;
1:seg7=7'b0000110;
2:seg7=7'b1011011;
3:seg7=7'b1001111;
4:seg7=7'b1100110;
5:seg7=7'b1101101;
6:seg7=7'b1111101;
7:seg7=7'b0000111;
8:seg7=7'b1111111;
9:seg7=7'b1101111;
default:seg7=7'b0000000;
endcase
end
endmodule
3、状态转化的代码是怎么书写的?
4、这段代码能解释一下吗?
module fdiv0(clk,pm,d,dout,rst);
input clk,rst;
input[3:0]d;
output pm;
output[3:0]dout;
reg[3:0]q1; reg full;
(*synthesis,keep*)wire ld;
always@(posedge clk, negedge rst) begin
if(!rst)begin q1<=0; full<=0;end
else if(ld)begin q1<=d; full<=1; end
else begin q1<=q1+1; full<=0; end
end
assign ld=(q1==4'b1111);
assign pm=full;
assign dout=q1;
endmodule
5、verilog的左移和右移应该怎么看呢,能分别举几个例子说明一下吗?