我是verilog的新用户。我想在verilog中读取和写入文本文件。成功地,我使用$fscan
从文本文件中读取输入。现在的问题是我无法将数据放入或写入输出文本文件。当我运行程序输出文件为空时
我在这里附上程序的源代码:
integer data_file ; // file handler
integer scan_file ; // file handler
reg [21:0] captured_data;
integer f;
reg [21:0] Add_num;
`define NULL 0
initial begin
data_file = $fopen("r.txt","r");
f = $fopen("output.txt","w");
if (data_file == `NULL)
begin
$display("data_file handle was NULL");
// $finish ;
end
end
always @(posedge clk) begin
scan_file = $fscanf(data_file, "%d\n", captured_data);
if (!$feof(data_file))
begin
//use captured_data as you would any other wire or reg value;
Add_num = captured_data + captured_data;
//out<=Add_num;
$display (" Data is = %d", Add_num );
$fwrite(f,"%d\n", Add_num);
end
end