此处需要注意verilog语言的文件路径和软件语言的文件路径的斜杠是相反的
initial
begin
fp_w=$fopen("D:/aaaaa/out.txt","wb");//以写的方式打开文件
end
always@(posedge clk_p or negedge rst_n)
begin
if(!rst_n)
begin
cnt <= 'b0;
end
else if(out_tvalid)
begin
cnt <= cnt +16'd1;
end
else
begin
cnt <= cnt;
end
end
reg [15:0] count;
always@(posedge clk_p)
begin
if((cnt < 10000)&&out_tvalid)
begin
$fwrite(fp_w,"%4x\n",out);
count <= count +1'd1;
end
else if(cnt>= 10000)
begin
$fclose(fp_w);
end
else
begin
count <= count;
end
end
参考文章:Verilog读写文件 - 码农教程