Verilog读取文本文件的问题

[复制链接]
9529|8
 楼主| swe21 发表于 2012-5-16 17:05 | 显示全部楼层 |阅读模式
本帖最后由 swe21 于 2012-5-16 17:08 编辑

大家好,verilog读取文本文件里面的数据,读到数据的末尾应该就不读了网上查了一下,$feof()命令有这个功能 ,当读到数据末尾时,
$feof(<文件句柄>)!=0,其他时候$feof(<文件句柄>)=0;
可是我用modelsim验证的时候为什么$feof()一直为零呢?
附上代码:
module file;
integer file,cnt;
reg [3:0] dat;
reg clk ;
reg en;
reg feof;
initial
clk = 0;
always #5 clk = ~clk;

initial begin

file = $fopen("data_in.txt","r");

feof = $feof(file);

if (file==0)

  begin

  $display("file open is failed");

  end

while(!$feof(file))begin

  @ (posedge clk)

  if(en)

cnt =
$fscanf( file,"%b",dat );

end
$fclose(file);
end
endmodule
GoldSunMonkey 发表于 2012-5-19 18:46 | 显示全部楼层
那你文件是不是空文件呢?
 楼主| swe21 发表于 2012-5-24 10:18 | 显示全部楼层
肯定不是空的哈
GoldSunMonkey 发表于 2012-5-24 14:47 | 显示全部楼层
从语法上看,我没看出问题。细节除外,我对Verilog只能做到看懂,我要提高。这个放着不说。

我感觉你的读的文件是空文件。或者说你没有放在应该的位置上。
 楼主| swe21 发表于 2012-5-24 22:17 | 显示全部楼层
谢谢猴哥,我在慢慢摸索下哈
a406023869 发表于 2012-5-25 10:38 | 显示全部楼层
会不会跟initial 只执行一次有关?
fangkunwei 发表于 2012-5-27 20:57 | 显示全部楼层
1# swe21
feof = $feof(file);

只执行了一次
被读文件与测试文件须在一个目录下
GoldSunMonkey 发表于 2012-5-28 12:07 | 显示全部楼层
从语法上看,我没看出问题。细节除外,我对Verilog只能做到看懂,我要提高。这个放着不说。

我感觉你的读的文件是空文件。或者说你没有放在应该的位置上。 ...
GoldSunMonkey 发表于 2012-5-24 14:47
看下文件的位置是不是在测试目录下。或者在代码里面加上文件的位置。
 楼主| swe21 发表于 2012-5-30 10:20 | 显示全部楼层
查了下资料,$feof()有这么一句说明
Fileio supports $feof which V2K does not.  Some functions such  as $fgetc return EOF (-1) but this is not the same.
V2K应该是verilog-2001不支持$feof吧,
谢谢楼上各位大侠们的帮助哈
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

25

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部