EGRE 631 - Virginia Commonwealth University



EGRE 631

Homework 03

Due 1/28/09

Add the function TO_ASCII to pkg_cnt1s.vhd in HW 03.zip. The function TO_ASCII should convert an input Hex nibble to an 8-bit ASCII byte. For example if the input is “1010” the returned value is “01000001”. Use tb_ascii_func.vhd in HW 03.zip to verify the TO_ASCII function.

-- Package containg gcnt1s.vcd

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

package pkg_cnt1s is

function gcnt1s(x: std_logic_vector) return integer;

function to_ascii(hex: std_logic_vector) return std_logic_vector;

end pkg_cnt1s;

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

package body pkg_cnt1s is

---------------------------------------------------------------

-- Function: TO_ASCII - Converts hex input nibble to ASCII

-- output byte.

-- Inputs: HEX - hex nibble

-- Outputs: ASCII - Corresponding ASCII byte

-- Requires: None

----------------------------------------------------------------

function to_ascii(hex: std_logic_vector) return std_logic_vector is

variable ascii : std_logic_vector(7 downto 0);

begin

if hex < "1010" then

ascii := hex + X"30";

else

ascii := hex + X"41" - 10;

end if;

return(ascii);

end;

end func;

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download