Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting STD_LOGIC_VECTOR to ASCII character

2,210 views
Skip to first unread message

Paul Grems Duncan

unread,
Nov 19, 1997, 3:00:00 AM11/19/97
to

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

Paul Grems Duncan

unread,
Nov 20, 1997, 3:00:00 AM11/20/97
to

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;

Paul Grems Duncan <gr...@swva.net> wrote in article
<01bcf485$08437e80$1fe08cd0@paul-s>...

0 new messages