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;
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.