Converting STD_LOGIC_VECTOR to ASCII character 
Author Message
 Converting STD_LOGIC_VECTOR to ASCII character

Greetings all,

I might be missing something here but I cannot seem to locate the library
function which takes the ASCII value in the form of SLV[15:0] and outputs
the ASCII character.  I *know* somebody has included this in one of the STD
or IEEE libraries; I just can't seem to find it.....

Any help?

TIA!

pgd

--
"In matters of style, swim with the current; in matters of principle, stand
like a rock."
 -- Thomas Jefferson

Paul Duncan
Airak Engineering
RR3 Box 533
415 Chestnut Avenue
New Castle, VA  24127-9519
grems at swva dot net



Sun, 07 May 2000 03:00:00 GMT  
 Converting STD_LOGIC_VECTOR to ASCII character

Hello all,

Here it the answer:

library IEEE;
use IEEE.STD_LOGIC_1164.all;

package CONVERTERS is
  function CONV   (SLV8 :STD_LOGIC_VECTOR (7 downto 0)) return CHARACTER;
  function CONV   (CHAR :CHARACTER)                     return
STD_LOGIC_VECTOR;
end CONVERTERS;

package body CONVERTERS is

----------------------------------------------------------------------------
--
  -- From STD_LOGIC_VECTOR to CHARACTER converter

----------------------------------------------------------------------------
--
  function CONV (SLV8 :STD_LOGIC_VECTOR (7 downto 0)) return CHARACTER is
    constant XMAP :INTEGER :=0;
    variable TEMP :INTEGER :=0;
  begin
    for i in SLV8'range loop
      TEMP:=TEMP*2;
      case SLV8(i) is
        when '0' | 'L'  => null;
        when '1' | 'H'  => TEMP :=TEMP+1;
        when others     => TEMP :=TEMP+XMAP;
      end case;
    end loop;
    return CHARACTER'VAL(TEMP);
  end CONV;

----------------------------------------------------------------------------
--
  -- From CHARACTER to STD_LOGIC_VECTOR (7 downto 0) converter

----------------------------------------------------------------------------
--
  function CONV (CHAR :CHARACTER) return STD_LOGIC_VECTOR is
    variable SLV8 :STD_LOGIC_VECTOR (7 downto 0);
    variable TEMP :INTEGER :=CHARACTER'POS(CHAR);
  begin
    for i in SLV8'reverse_range loop
      case TEMP mod 2 is
        when 0 => SLV8(i):='0';
        when 1 => SLV8(i):='1';
        when others => null;
      end case;
      TEMP:=TEMP/2;
    end loop;
    return SLV8;
  end CONV;

end CONVERTERS;



Quote:
> Greetings all,

> I might be missing something here but I cannot seem to locate the library
> function which takes the ASCII value in the form of SLV[15:0] and outputs
> the ASCII character.  I *know* somebody has included this in one of the
STD
> or IEEE libraries; I just can't seem to find it.....

> Any help?

> TIA!

> pgd

> --
> "In matters of style, swim with the current; in matters of principle,
stand
> like a rock."
>  -- Thomas Jefferson

> Paul Duncan
> Airak Engineering
> RR3 Box 533
> 415 Chestnut Avenue
> New Castle, VA  24127-9519
> grems at swva dot net



Mon, 08 May 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Summary: convert character to ASCII code?

2. Help: convert character to ASCII code?

3. Newbie: converting character to ascii representation

4. convert character to ascii

5. Converting Character to ASCII in 8086, Help! (again)

6. Convert Character to ASCII code in 8086 Help!

7. Converting hex digit to ASCII character

8. Converting hex digit to ASCII character

9. Converting ASCII characters <-> binary string

10. Converting Characters to Ascii code

11. Convert character to ascii value

12. Converting foreign characters to HTML characters entities

 

 
Powered by phpBB® Forum Software