1、$fwrite 向文件写入数据 格式:$fwrite(fid,"%h%h\n",dout_r1,dout_r2);(1)fwrite是需要触发条件的,在一次触发条件之后也不会自动发生换行,所以要求手动添加换行。(2)如果写放文件的格式为%d,则认为是无符号数,如下例:wire [27:0] data;fp_re = $fopen("dout.txt","w");always @(posedge clk) begin if(dout_rdy == 1‘b1) begin $fwrite(fileid,"%d",data); end end解决方法是:将 data定义为有符号数,即:wire signed [27:0] data; 2、$fscanf 从文件中读取数据(1)读取格式为按行读取,一行读完之后再转向下一行;(2)读取也是需要触发条件的; always @ ( posedge clk ) begin if(cnt_test == 3‘d7) begin $fscanf(coef_file,"%d%d%d%d",coef01_i,coef01_q,coef02_i,coef02_q); $fscanf(ref_file,"%d%d%d%d",ref01_i,ref01_q,ref02_i,ref02_q); end end
时间: 2024-10-18 19:20:49