spandana51
Newbie level 3
- Joined
- Aug 5, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 44
I have written a code to read text and to write the same text to the other text file and i want to convert each character read from the input text to an corresponding binary value. And the reading and writing text perfectly worked but the problem is it is showing only the value corresponding to the first character in the text. Please give me the idea where i am doing the mistake. Here's my code:
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use std.textio.all; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity asconvbin is Port ( clk : in STD_LOGIC; d : out STD_LOGIC_VECTOR(7 downto 0)); end asconvbin; architecture Behavioral of asconvbin is begin process(clk) variable OUTLINE : LINE; file FILEOUT : TEXT is OUT "outputfile.txt"; --Input variables variable inline:line; variable char:character; variable end_of_line:boolean; file myfile:text is "myfile.txt"; variable k:integer; begin if rising_edge(clk) then while not endfile(myfile) loop readline(myfile,inline); k:=inline'high; end_of_line := true; while end_of_line loop read(inline,char,end_of_line); for i in k downto 0 loop if char='A' then d<="01000000"; elsif char='B' then d<="01000001"; elsif char='C' then d<="01000010"; elsif char='D' then d<="01000011"; elsif char='E' then d<="01000100"; elsif char='F' then d<="01000101"; elsif char='G' then d<="01000110"; elsif char='H' then d<="01000111"; elsif char='I' then d<="01001000"; elsif char='J' then d<="01001001"; elsif char='K' then d<="01001010"; elsif char='L' then d<="01001011"; elsif char='M' then d<="01001100"; elsif char='N' then d<="01001101"; elsif char='O' then d<="01001110"; elsif char='P' then d<="01001111"; elsif char='Q' then d<="01010000"; elsif char='R' then d<="01010001"; elsif char='S' then d<="01010010"; elsif char='T' then d<="01010011"; elsif char='U' then d<="01010100"; elsif char='V' then d<="01010101"; elsif char='W' then d<="01010110"; elsif char='X' then d<="01010111"; elsif char='Y' then d<="01011000"; elsif char='Z' then d<="01011001"; else null; end if; k:=k-1; end loop; if end_of_line then WRITE(OUTLINE,char); end if; end loop; end loop; WRITELINE(FILEOUT, OUTLINE); --writes outline variable to file. --end loop; end if; end process; end Behavioral;
Last edited by a moderator: