程序如下:module ad_driver2(clk,rst_n,sdata_in,sdata_out,cs_n,sclk
);
input clk;
input rst_n;
input sdata_in;
output cs_n;
output sdata_out;
output sclk;
reg cs_n;
reg [2:0] count=0;
reg [4:0] cnt=0;
reg [15:0] sdata_out_buffer=0;
reg sclk_buffer=0;
reg state,next_state=0;
always @(posedge clk)
begin
if(!rst_n)begin
count<=0;
sclk_buffer<=0;
end
else begin
if(count==3'b111)begin
count<=3'b000;
sclk_buffer<=~sclk_buffer;
end
else begin
count<=count+3'b001;
end
end
end
always @(negedge sclk_buffer)begin
if(!rst_n)
cnt<=0;
else
if(cnt==17)
cnt<=0;
else
cnt<=cnt+1;
end
always @(negedge sclk_buffer)begin
if(!rst_n)
state<=1'b0;
else
state<=next_state;
end
always @(state,cnt)begin
case(state)
1'b0: begin
if(cnt==1)
next_state=1'b1;
else
next_state=1'b0;
end
1'b1: begin
if(cnt==17)
next_state=1'b0;
else
next_state=1'b1;
end
endcase
end
always @(negedge sclk_buffer)begin
case (next_state)
1'b0:begin
cs_n<=1;
sdata_out_buffer<=0;
end
1'b1:begin
cs_n<=0;
sdata_out_buffer<={sdata_out_buffer[14:0],sdata_in};
end
endcase
end
assign sclk=sclk_buffer;
assign sdata_out=sdata_out_buffer;
endmodule
adata_out输出应该是个数?为什么仿真出来的是这样好像只是sdata_buffer[0],是我程序写错了还是仿真哪块设置的不对?
|