Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.82 KB | None | 0 0
  1. LIBRARY ieee;
  2.     USE ieee.std_logic_1164.all;
  3.     use ieee.numeric_std.ALL;
  4.     use ieee.std_logic_arith.all;
  5.  
  6. entity UART is
  7.     port (
  8.         clk_10mhz: in STD_LOGIC;
  9.         uart_clk: out STD_LOGIC;
  10.         txPin: out STD_LOGIC
  11.     );
  12. end entity;
  13.  
  14. architecture Test of UART is
  15.     signal txStart: STD_LOGIC := '0';
  16.     signal txIdle: STD_LOGIC;
  17.     signal txData: STD_LOGIC_VECTOR(7 downto 0);
  18.    
  19.     component TX is
  20.         port (
  21.             clk_in: in STD_LOGIC;
  22.             start: in STD_LOGIC;
  23.             data: in STD_LOGIC_VECTOR(7 downto 0);
  24.             tx: out STD_LOGIC;
  25.             txIdle: out STD_LOGIC;
  26.             debug_clk: out STD_LOGIC
  27.         );
  28.     end component TX;
  29.  
  30.    
  31. begin
  32.     process (clk_10mhz)
  33.         variable clkDividerCounter : integer range 0 to 10000000;
  34.         variable textToSend : string(1 to 31) := " " & LF & CR;
  35.         variable currentCharacterIndex : integer range 1 to 31 := 1;
  36.         variable startSending : std_logic := '0';
  37.         variable characterReceivedByTX : std_logic := '1';
  38.     begin      
  39.         if (rising_edge(clk_10mhz)) then
  40.             if (startSending = '1') then
  41.                 if (txIdle = '0') then
  42.                     characterReceivedByTX := '1';
  43.                 end if;
  44.            
  45.                 if (txIdle = '1' and characterReceivedByTX = '1') then
  46.                     txData <= CONV_STD_LOGIC_VECTOR(character'pos(textToSend(currentCharacterIndex)),8);
  47.                     txStart <= '1';
  48.                
  49.                     if (currentCharacterIndex < 31) then
  50.                         currentCharacterIndex := currentCharacterIndex + 1;
  51.                         characterReceivedByTX := '0';
  52.                     else
  53.                         txStart <= '0';
  54.                         currentCharacterIndex := 1;
  55.                         startSending := '0';
  56.                     end if;
  57.                 end if;
  58.             else
  59.                 if (clkDividerCounter < 10000000) then
  60.                     clkDividerCounter := clkDividerCounter + 1;
  61.                     startSending := '0';
  62.                 else
  63.                     clkDividerCounter := 0;
  64.                     startSending := '1';
  65.                 end if;
  66.             end if;
  67.         end if;
  68.     end process;
  69.    
  70.    
  71.     u1: TX port map (clk_10mhz, txStart, txData, txPin, txIdle, uart_clk);
  72. end Test;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement