Wednesday, 2 November 2016

Reading a single character From a text Document




--There should be a file aabc_file.txt containing that character

library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;

entity read_character is
end read_character;

architecture behavioral of read_character is
    signal d_out:   character;
    signal clk:     std_logic := '0';
begin
reading:
    process
        constant filename:  string := "aabc_file.txt";
        file f:              text open read_mode is filename;
        variable L:          line;
        variable data_read:  character;
        variable char:      character;
        variable len:       integer;
    begin
        while not endfile(f) loop
            readline(f, L);

            len := L'length;
            while len > 0 loop
                read (L, data_read);
                len := L'length;
                if len > 0 then
                    read (L, char);
                    len := L'length;
                end if;
                wait until rising_edge(clk);
                d_out <= data_read;
                report "data_read = " & character'image(data_read);
            end loop;
        end loop;
        wait until rising_edge(clk);
        wait;                
    end process;
CLOCK:
    process
    begin
        wait for 5 ns;
        clk <= not clk;
        if Now > 250 ns then
            wait;
        end if;
    end process;

end behavioral;

No comments:

Post a Comment