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.

storing .txt file in an array..

Status
Not open for further replies.

chat

Member level 5
Joined
Mar 17, 2011
Messages
84
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,888
hi all !
i have made a part of a program to read a text file from a specified location , and i want to store it an array .. i don't know how to do this...please help me..

here is the code for reading a file..


Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_textio.all;

Port ( adr: in std_logic_vector(7 downto 0);
data : out std_logic_vector(11 downto 0);
clk: in std_logic);
end rom;

architecture Behavioral of rom is
	file datafile: text is "c:\read.txt";
	type memorytype is array(0 to 255) of std_logic_vector(11 downto 0);
	signal rom: memorytype;
	signal integer_address: integer range 0 to 255;

begin
	clkedge: process(clk)
		begin
			if rising_edge(clk) then
				integer_address <= to_integer(adr);
			end if;
	end process clkedge;

end Behavioral;
 

first of all it depends how the data is stored in the text file. Is it binary or hex or integer?
 

its in bit form like

0001
0011
0111
.....etc.
 

to read a text file, you need to use the textio library:

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;

use std.textio.all;

.......

process
  file datafile : text open READ_MODE is "c:\read.txt";
  variable inline : line;
begin
  
  for i in memorytype'range loop
    readline(datafile, inline);
    read(inline, (memorytype(i));
  end loop;
end process;

This code assumes there are 12 bits on each line to fill each std_logic_vector.
 

hi tricky this program runs fine but i want to use an array...
 

This is reading the text file directly into your array.
 

ok.. what will be the modifications in writing ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top