This UART is able to Transmit/Receive bytes in the configuration:
1 start bit - no parity - 1 stop bit.
It can be commanded by a microcontroller, or by other IP core.
It is not suited to interface a modem as there is no control handshaking (CTS/RTS).
It does'nt contain FIFO for emit/receive.
Het volledige project vind je op: http://www.opencores.org/cvsweb.shtml/MiniUART/
Ik zou nu een extra functie willen inbouwen zodanig dat een 4-bit hex 'string' wordt omgezet in een 7-bit 'char string'. Heb volgende code gevonden om dit te verwezenlijken:
Code: Selecteer alles
------------------------------------------------------------------------
--
-- ***Author***
-- Jan De Ceuster
--
-- *** File ***
-- ASCII_functions.vhd
--
-- *** Functions ***
-- ASCII2HEX_f
-- input : std_logic_vector of size n*7
-- return : std_logic_vector of size n*4 (n*4-1 downto 0)
--
-- HEX2ASCII_f
-- input : std_logic_vector of size n*4
-- return : std_logic_vector of size n*7 (n*7-1 downto 0)
--
-- HEX2ASCII_f
-- input : std_logic_vector of size n*4
-- return : string of size n (1 to n)
--
-- *** Description ***
--
-- *** History ***
-- 001 initial
library ieee;
use ieee.std_logic_1164.all;
library nicethings;
use nicethings.ASCII_constants.all;
package ASCII_functions is
function ASCII2HEX_f(ASCII : std_logic_vector)
return std_logic_vector;
function ASCII2HEX_f(ASCII : std_logic_vector; size : integer)
return std_logic_vector;
function HEX2ASCII_f(HEX : std_logic_vector)
return std_logic_vector;
function HEX2ASCII_f(HEX : std_logic_vector; size : integer)
return std_logic_vector;
function HEX2ASCII_f(HEX : std_logic_vector)
return string;
end package;
package body ASCII_functions is
function ASCII2HEX_f(ASCII : std_logic_vector)
return std_logic_vector is
begin
return ASCII2HEX_f(ASCII,7);
end function;
function ASCII2HEX_f(ASCII : std_logic_vector; size : integer)
return std_logic_vector is
constant length : integer := (ASCII'high - ASCII'low + 1)/7;
variable HEXoffset, ASCIIoffset : integer;
variable HEX : std_logic_vector(length*4-1 downto 0);
variable temp : std_logic_vector(4 downto 0);
begin
for count in length-1 downto 0 loop
HEXoffset := count*4;
ASCIIoffset := count*size;
temp := ASCII(ASCIIoffset+4+ASCII'low downto ASCIIoffset+ASCII'low);
case temp is
when C_ASCII_0x0 => HEX(HEXoffset+3 downto HEXoffset) := "0000";
when C_ASCII_0x1 => HEX(HEXoffset+3 downto HEXoffset) := "0001";
when C_ASCII_0x2 => HEX(HEXoffset+3 downto HEXoffset) := "0010";
when C_ASCII_0x3 => HEX(HEXoffset+3 downto HEXoffset) := "0011";
when C_ASCII_0x4 => HEX(HEXoffset+3 downto HEXoffset) := "0100";
when C_ASCII_0x5 => HEX(HEXoffset+3 downto HEXoffset) := "0101";
when C_ASCII_0x6 => HEX(HEXoffset+3 downto HEXoffset) := "0110";
when C_ASCII_0x7 => HEX(HEXoffset+3 downto HEXoffset) := "0111";
when C_ASCII_0x8 => HEX(HEXoffset+3 downto HEXoffset) := "1000";
when C_ASCII_0x9 => HEX(HEXoffset+3 downto HEXoffset) := "1001";
when C_ASCII_0xA => HEX(HEXoffset+3 downto HEXoffset) := "1010";
when C_ASCII_0xB => HEX(HEXoffset+3 downto HEXoffset) := "1011";
when C_ASCII_0xC => HEX(HEXoffset+3 downto HEXoffset) := "1100";
when C_ASCII_0xD => HEX(HEXoffset+3 downto HEXoffset) := "1101";
when C_ASCII_0xE => HEX(HEXoffset+3 downto HEXoffset) := "1110";
when C_ASCII_0xF => HEX(HEXoffset+3 downto HEXoffset) := "1111";
when others => HEX(HEXoffset+3 downto HEXoffset) := "----";
end case;
end loop;
return HEX;
end function;
function HEX2ASCII_f(HEX : std_logic_vector)
return std_logic_vector is
begin
return HEX2ASCII_f(HEX,7);
end function;
function HEX2ASCII_f(HEX : std_logic_vector; size : integer)
return std_logic_vector is
constant length : integer := (HEX'high - HEX'low + 1)/4;
variable ASCII : std_logic_vector(length*7-1 downto 0) := (others => '0');
variable ASCIIoffset, HEXoffset : integer;
variable temp : std_logic_vector(3 downto 0);
begin
for count in length-1 downto 0 loop
ASCIIoffset := count*size;
HEXoffset := count*4;
temp := HEX(HEXoffset+3+HEX'low downto HEXoffset+HEX'low);
case temp is
when "0000" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_0;
when "0001" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_1;
when "0010" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_2;
when "0011" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_3;
when "0100" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_4;
when "0101" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_5;
when "0110" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_6;
when "0111" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_7;
when "1000" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_8;
when "1001" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_9;
when "1010" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_A;
when "1011" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_B;
when "1100" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_C;
when "1101" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_D;
when "1110" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_E;
when "1111" => ASCII(ASCIIoffset+6 downto ASCIIoffset) := C_ASCII_CAPITAL_F;
when others => ASCII(ASCIIoffset+6 downto ASCIIoffset) := "-------";
end case;
end loop;
return ASCII;
end function;
function HEX2ASCII_f(HEX : std_logic_vector)
return string is
constant size : integer := HEX'high - HEX'low + 1;
variable ASCII : string(1 to size/4);
variable offset,offset2 : integer;
variable temp : std_logic_vector(3 downto 0);
begin
for count in size/4-1 downto 0 loop
offset := size/4-count;
offset2 := count*4;
temp := HEX(offset2+3+HEX'low downto offset2+HEX'low);
case temp is
when "0000" => ASCII(offset) := '0';
when "0001" => ASCII(offset) := '1';
when "0010" => ASCII(offset) := '2';
when "0011" => ASCII(offset) := '3';
when "0100" => ASCII(offset) := '4';
when "0101" => ASCII(offset) := '5';
when "0110" => ASCII(offset) := '6';
when "0111" => ASCII(offset) := '7';
when "1000" => ASCII(offset) := '8';
when "1001" => ASCII(offset) := '9';
when "1010" => ASCII(offset) := 'A';
when "1011" => ASCII(offset) := 'B';
when "1100" => ASCII(offset) := 'C';
when "1101" => ASCII(offset) := 'D';
when "1110" => ASCII(offset) := 'E';
when "1111" => ASCII(offset) := 'F';
when others => ASCII(offset) := '?';
end case;
end loop;
return ASCII;
end function;
end ASCII_functions;
------------------------------------------------------------------------
--
-- ***Author***
-- Jan De Ceuster
--
-- *** File ***
-- ASCII_constants.vhd
--
-- *** Entity ***
--
-- *** Port list ***
--
-- *** Description ***
--
-- *** History ***
--
library ieee;
use ieee.std_logic_1164.all;
package ASCII_constants is
-- TAPState constants, used for synthesis purposes
constant C_ASCII_nul : std_logic_vector(6 downto 0) := "0000000";
constant C_ASCII_soh : std_logic_vector(6 downto 0) := "0000001";
constant C_ASCII_stx : std_logic_vector(6 downto 0) := "0000010";
constant C_ASCII_etx : std_logic_vector(6 downto 0) := "0000011";
constant C_ASCII_eot : std_logic_vector(6 downto 0) := "0000100";
constant C_ASCII_enq : std_logic_vector(6 downto 0) := "0000101";
constant C_ASCII_ack : std_logic_vector(6 downto 0) := "0000110";
constant C_ASCII_bel : std_logic_vector(6 downto 0) := "0000111";
constant C_ASCII_bs : std_logic_vector(6 downto 0) := "0001000";
constant C_ASCII_ht : std_logic_vector(6 downto 0) := "0001001";
constant C_ASCII_lf : std_logic_vector(6 downto 0) := "0001010";
constant C_ASCII_vt : std_logic_vector(6 downto 0) := "0001011";
constant C_ASCII_np : std_logic_vector(6 downto 0) := "0001100";
constant C_ASCII_cr : std_logic_vector(6 downto 0) := "0001101";
constant C_ASCII_so : std_logic_vector(6 downto 0) := "0001110";
constant C_ASCII_si : std_logic_vector(6 downto 0) := "0001111";
constant C_ASCII_dle : std_logic_vector(6 downto 0) := "0010000";
constant C_ASCII_dc1 : std_logic_vector(6 downto 0) := "0010001";
constant C_ASCII_dc2 : std_logic_vector(6 downto 0) := "0010010";
constant C_ASCII_dc3 : std_logic_vector(6 downto 0) := "0010011";
constant C_ASCII_dc4 : std_logic_vector(6 downto 0) := "0010100";
constant C_ASCII_nak : std_logic_vector(6 downto 0) := "0010101";
constant C_ASCII_syn : std_logic_vector(6 downto 0) := "0010110";
constant C_ASCII_etb : std_logic_vector(6 downto 0) := "0010111";
constant C_ASCII_can : std_logic_vector(6 downto 0) := "0011000";
constant C_ASCII_em : std_logic_vector(6 downto 0) := "0011001";
constant C_ASCII_sub : std_logic_vector(6 downto 0) := "0011010";
constant C_ASCII_esc : std_logic_vector(6 downto 0) := "0011011";
constant C_ASCII_fs : std_logic_vector(6 downto 0) := "0011100";
constant C_ASCII_gs : std_logic_vector(6 downto 0) := "0011101";
constant C_ASCII_rs : std_logic_vector(6 downto 0) := "0011110";
constant C_ASCII_us : std_logic_vector(6 downto 0) := "0011111";
constant C_ASCII_sp : std_logic_vector(6 downto 0) := "0100000";
constant C_ASCII_exclamationmark : std_logic_vector(6 downto 0) := "0100001";
constant C_ASCII_quotationmark : std_logic_vector(6 downto 0) := "0100010";
constant C_ASCII_number : std_logic_vector(6 downto 0) := "0100011";
constant C_ASCII_dollar : std_logic_vector(6 downto 0) := "0100100";
constant C_ASCII_percent : std_logic_vector(6 downto 0) := "0100101";
constant C_ASCII_ampersand : std_logic_vector(6 downto 0) := "0100110";
constant C_ASCII_apstrophe : std_logic_vector(6 downto 0) := "0100111";
constant C_ASCII_lparenthesis : std_logic_vector(6 downto 0) := "0101000";
constant C_ASCII_rparenthesis : std_logic_vector(6 downto 0) := "0101001";
constant C_ASCII_astrix : std_logic_vector(6 downto 0) := "0101010";
constant C_ASCII_plus : std_logic_vector(6 downto 0) := "0101011";
constant C_ASCII_comma : std_logic_vector(6 downto 0) := "0101100";
constant C_ASCII_minus : std_logic_vector(6 downto 0) := "0101101";
constant C_ASCII_fullstop : std_logic_vector(6 downto 0) := "0101110";
constant C_ASCII_slash : std_logic_vector(6 downto 0) := "0101111";
constant C_ASCII_0 : std_logic_vector(6 downto 0) := "0110000";
constant C_ASCII_1 : std_logic_vector(6 downto 0) := "0110001";
constant C_ASCII_2 : std_logic_vector(6 downto 0) := "0110010";
constant C_ASCII_3 : std_logic_vector(6 downto 0) := "0110011";
constant C_ASCII_4 : std_logic_vector(6 downto 0) := "0110100";
constant C_ASCII_5 : std_logic_vector(6 downto 0) := "0110101";
constant C_ASCII_6 : std_logic_vector(6 downto 0) := "0110110";
constant C_ASCII_7 : std_logic_vector(6 downto 0) := "0110111";
constant C_ASCII_8 : std_logic_vector(6 downto 0) := "0111000";
constant C_ASCII_9 : std_logic_vector(6 downto 0) := "0111001";
constant C_ASCII_colon : std_logic_vector(6 downto 0) := "0111010";
constant C_ASCII_semicolon : std_logic_vector(6 downto 0) := "0111011";
constant C_ASCII_lessthan : std_logic_vector(6 downto 0) := "0111100";
constant C_ASCII_equal : std_logic_vector(6 downto 0) := "0111101";
constant C_ASCII_greaterthan : std_logic_vector(6 downto 0) := "0111110";
constant C_ASCII_questionmark : std_logic_vector(6 downto 0) := "0111111";
constant C_ASCII_at : std_logic_vector(6 downto 0) := "1000000";
constant C_ASCII_CAPITAL_A : std_logic_vector(6 downto 0) := "1000001";
constant C_ASCII_CAPITAL_B : std_logic_vector(6 downto 0) := "1000010";
constant C_ASCII_CAPITAL_C : std_logic_vector(6 downto 0) := "1000011";
constant C_ASCII_CAPITAL_D : std_logic_vector(6 downto 0) := "1000100";
constant C_ASCII_CAPITAL_E : std_logic_vector(6 downto 0) := "1000101";
constant C_ASCII_CAPITAL_F : std_logic_vector(6 downto 0) := "1000110";
constant C_ASCII_CAPITAL_G : std_logic_vector(6 downto 0) := "1000111";
constant C_ASCII_CAPITAL_H : std_logic_vector(6 downto 0) := "1001000";
constant C_ASCII_CAPITAL_I : std_logic_vector(6 downto 0) := "1001001";
constant C_ASCII_CAPITAL_J : std_logic_vector(6 downto 0) := "1001010";
constant C_ASCII_CAPITAL_K : std_logic_vector(6 downto 0) := "1001011";
constant C_ASCII_CAPITAL_L : std_logic_vector(6 downto 0) := "1001100";
constant C_ASCII_CAPITAL_M : std_logic_vector(6 downto 0) := "1001101";
constant C_ASCII_CAPITAL_N : std_logic_vector(6 downto 0) := "1001110";
constant C_ASCII_CAPITAL_O : std_logic_vector(6 downto 0) := "1001111";
constant C_ASCII_CAPITAL_P : std_logic_vector(6 downto 0) := "1010000";
constant C_ASCII_CAPITAL_Q : std_logic_vector(6 downto 0) := "1010001";
constant C_ASCII_CAPITAL_R : std_logic_vector(6 downto 0) := "1010010";
constant C_ASCII_CAPITAL_S : std_logic_vector(6 downto 0) := "1010011";
constant C_ASCII_CAPITAL_T : std_logic_vector(6 downto 0) := "1010100";
constant C_ASCII_CAPITAL_U : std_logic_vector(6 downto 0) := "1010101";
constant C_ASCII_CAPITAL_V : std_logic_vector(6 downto 0) := "1010110";
constant C_ASCII_CAPITAL_W : std_logic_vector(6 downto 0) := "1010111";
constant C_ASCII_CAPITAL_X : std_logic_vector(6 downto 0) := "1011000";
constant C_ASCII_CAPITAL_Y : std_logic_vector(6 downto 0) := "1011001";
constant C_ASCII_CAPITAL_Z : std_logic_vector(6 downto 0) := "1011010";
constant C_ASCII_lsquarebracket : std_logic_vector(6 downto 0) := "1011011";
constant C_ASCII_backslash : std_logic_vector(6 downto 0) := "1011100";
constant C_ASCII_rsquarebracket : std_logic_vector(6 downto 0) := "1011101";
constant C_ASCII_circumflex : std_logic_vector(6 downto 0) := "1011110";
constant C_ASCII_underscore : std_logic_vector(6 downto 0) := "1011111";
constant C_ASCII_grave : std_logic_vector(6 downto 0) := "1100000";
constant C_ASCII_a : std_logic_vector(6 downto 0) := "1100001";
constant C_ASCII_b : std_logic_vector(6 downto 0) := "1100010";
constant C_ASCII_c : std_logic_vector(6 downto 0) := "1100011";
constant C_ASCII_d : std_logic_vector(6 downto 0) := "1100100";
constant C_ASCII_e : std_logic_vector(6 downto 0) := "1100101";
constant C_ASCII_f : std_logic_vector(6 downto 0) := "1100110";
constant C_ASCII_g : std_logic_vector(6 downto 0) := "1100111";
constant C_ASCII_h : std_logic_vector(6 downto 0) := "1101000";
constant C_ASCII_i : std_logic_vector(6 downto 0) := "1101001";
constant C_ASCII_j : std_logic_vector(6 downto 0) := "1101010";
constant C_ASCII_k : std_logic_vector(6 downto 0) := "1101011";
constant C_ASCII_l : std_logic_vector(6 downto 0) := "1101100";
constant C_ASCII_m : std_logic_vector(6 downto 0) := "1101101";
constant C_ASCII_n : std_logic_vector(6 downto 0) := "1101110";
constant C_ASCII_o : std_logic_vector(6 downto 0) := "1101111";
constant C_ASCII_p : std_logic_vector(6 downto 0) := "1110000";
constant C_ASCII_q : std_logic_vector(6 downto 0) := "1110001";
constant C_ASCII_r : std_logic_vector(6 downto 0) := "1110010";
constant C_ASCII_s : std_logic_vector(6 downto 0) := "1110011";
constant C_ASCII_t : std_logic_vector(6 downto 0) := "1110100";
constant C_ASCII_u : std_logic_vector(6 downto 0) := "1110101";
constant C_ASCII_v : std_logic_vector(6 downto 0) := "1110110";
constant C_ASCII_w : std_logic_vector(6 downto 0) := "1110111";
constant C_ASCII_x : std_logic_vector(6 downto 0) := "1111000";
constant C_ASCII_y : std_logic_vector(6 downto 0) := "1111001";
constant C_ASCII_z : std_logic_vector(6 downto 0) := "1111010";
constant C_ASCII_lcurlybracket : std_logic_vector(6 downto 0) := "1111011";
constant C_ASCII_verticalbar : std_logic_vector(6 downto 0) := "1111100";
constant C_ASCII_rcurlybracket : std_logic_vector(6 downto 0) := "1111101";
constant C_ASCII_tilde : std_logic_vector(6 downto 0) := "1111110";
constant C_ASCII_del : std_logic_vector(6 downto 0) := "1111111";
constant C_ASCII_0x0 : std_logic_vector(4 downto 0) := "10000";
constant C_ASCII_0x1 : std_logic_vector(4 downto 0) := "10001";
constant C_ASCII_0x2 : std_logic_vector(4 downto 0) := "10010";
constant C_ASCII_0x3 : std_logic_vector(4 downto 0) := "10011";
constant C_ASCII_0x4 : std_logic_vector(4 downto 0) := "10100";
constant C_ASCII_0x5 : std_logic_vector(4 downto 0) := "10101";
constant C_ASCII_0x6 : std_logic_vector(4 downto 0) := "10110";
constant C_ASCII_0x7 : std_logic_vector(4 downto 0) := "10111";
constant C_ASCII_0x8 : std_logic_vector(4 downto 0) := "11000";
constant C_ASCII_0x9 : std_logic_vector(4 downto 0) := "11001";
constant C_ASCII_0xA : std_logic_vector(4 downto 0) := "00001";
constant C_ASCII_0xB : std_logic_vector(4 downto 0) := "00010";
constant C_ASCII_0xC : std_logic_vector(4 downto 0) := "00011";
constant C_ASCII_0xD : std_logic_vector(4 downto 0) := "00100";
constant C_ASCII_0xE : std_logic_vector(4 downto 0) := "00101";
constant C_ASCII_0xF : std_logic_vector(4 downto 0) := "00110";
end ASCII_constants;
package body ASCII_constants is
end ASCII_constants;
------------------------------------------------------------------------
Het mag ook een andere conversie functie zijn. Weet iemand waar ik deze kan vinden of heeft hier iemand de kennis om zo'n functie-tje te schrijven zodat die kan worden ingepast in de bestaande core?