Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using $fgetc to read characters in verilog

Status
Not open for further replies.

anhnha

Full Member level 6
Full Member level 6
Joined
Mar 8, 2012
Messages
322
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Visit site
Activity points
3,684
Hi all,
I am learning verilog and this is a module used for read a character:
Code:
module file_read()

parameter EOF = -1;

integer file_handle,error,indx;
reg signed [15:0] wide_char;
reg [7:0] mem[0:255];
reg [639:0] err_str;

initial begin
  indx=0;
  file_handle = $fopen(“text.txt”,”r”);
  error = $ferror(file_handle,err_str);
  if (error==0) begin
    wide_char = 16’h0000;
    while (wide_char!=EOF) begin
       wide_char = $fgetc(file_handle);
      mem[indx] = wide_char[7:0];
      $write(“%c”,mem[indx]);
      indx = indx + 1;
    end
  end
  else $display(“Can’t open file…”);
  $fclose(file_handle);
end
endmodule
I have a problem in understanding the code, hope anyone can help me out.
1) Why we need wide_char[15:0] and why signed? A character is only one byte(8 bits)
2) What is reg [639:0] err_str is used for? And why here is [639:0], where it come from?
Thank you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top